[Tutor] accessing Postgres db results by column name

Serdar Tumgoren zstumgoren at gmail.com
Fri Apr 9 22:42:24 CEST 2010

Hi folks,

Does anyone know if there's native support in psycopg2 for accessing rows in
a result-set by column name (rather than by index)?

I'd like to be able to do something like below:

cur.execute('select id, name from mytable')
data = cur.fetchall()
for row in data:
    print row['id'], row['name']

The functionality I have in mind is built into sqlite3:


And there are a few Python recipes that let you mimic this behavior:



But I'm wondering if any Postgres db adapters offer native support, similar
to sqlite3? I didn't notice it in a quick scan of the psycopg2 docs (
http://initd.org/psycopg/docs/), but perhaps the functionality is not
documented or someone knows of a different Postgres adapter that has this

As always, any pointers are greatly appreciated!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100409/1da836a5/attachment.html>

More information about the Tutor mailing list