Accessing PostgreSQL 9 with Python via Psycopg2

Wednesday, December 15, 2010

install psycopg2 via easy_install:

easy_install psycopg2

test in python shell:

>>> import psycopg2
>>> conn = psycopg2.connect(database='mydb')
>>> cur = conn.cursor()
>>> cur.execute('''select * from users''')
>>> for row in cur.fetchall():
...     print row[0], row[1]
... 
1 eric
2 lxneng
3 luoxiaoneng
>>> cur.close()
>>> conn.close()

This entry was tagged PostgreSQL, PSQL and Python

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top