Accessing PostgreSQL with Python and Psycopg2 : Page 3

The combination of Python and PostgreSQL is potent, particularly when you use the Psycopg2 driver.

by Joshua D. Drake

Aug 26, 2005

Page 3 of 3

Using Named Columns
Some programmers would prefer to not use numeric column representations such as row[1][1]; instead, it can be easier to use a dictionary. Here's the same example with a slight modification that uses the column name rather than the column index number:

The cur.executemany statement automatically iterates through the dictionary and executes the INSERT query for each row.

The only downside to using Psycopg2 and PostgreSQL is that the driver is a little behind in terms of server-side support functions such as prepared queries, but the author of Psycopg2 expects to implement those features in the near future.