Created
December 9, 2015 07:26
-
-
Save vitqst/f82634f0f05b8f6fd7d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #connect to postgres | |
| import psycopg2 | |
| try: | |
| conn = psycopg2.connect("dbname='databasename' user='user_name' host='localhost' password='pass'") | |
| except: | |
| print ("I am unable to connect to the database") | |
| cur = conn.cursor() | |
| cur.execute("SELECT * FROM table") #query | |
| rows = cur.fetchall() #fetch array list | |
| for row in rows: | |
| print ("email = ", row[4], "\n") | |
| conn.commit() | |
| conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment