Created
March 14, 2018 15:32
-
-
Save yglodt/409ea74b3e7da42554789623d61fbefe to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import psycopg2 | |
import sys | |
con = None | |
conn_string = "host='localhost' dbname='mydb' user='myuser' password='mypass'" | |
try: | |
con = psycopg2.connect(conn_string) | |
cur = con.cursor() | |
#cur.execute('SELECT version()') | |
#ver = cur.fetchone() | |
#print ver | |
cur.execute('SELECT id, name from address order by name') | |
rows = cur.fetchall() | |
for row in rows: | |
print row[0], " ", row[1] | |
except psycopg2.DatabaseError, e: | |
print 'Error %s' % e | |
sys.exit(1) | |
finally: | |
if con: | |
con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment