[DB-SIG] Python database API 2.0/returning Column names with data

D'Arcy J.M. Cain darcy@druid.net
Fri, 2 Nov 2001 07:03:40 -0500 (EST)

Thus spake Gary Maynard
>   We are trying to implement a method whereby we can return data from =
> the database in key value dictionary pairs.
> so for example we have a table something like this:
> Table: Address
> Name varchar(20),
> Street varchar(20),
> Town varchar(20),
> ccode char(2)
> and we want to return the data into a dictionary so that we also have =
> access to the column title.  For example, let's say we query the =
> database with something like this:
> result =3D cursor.fetchall("select * from Address")
> Then we'd like to put the data from result into another data object, =
> call it sorted_result.  We'd like to include the column names in this =
> object such that we could obtain any piece of data by giving it the row =
> number and column name.  So, if we wanted to obtain the Street of the =
> 6th row, we would say something like:
> sorted_result [6]['Street']

This is exactly what the dictresult() method in "Classic" PyGreSQL does.
See http://druid.net/pygresql/ for details.

D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.