Select as dictionary...
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Oct 1 09:50:59 EDT 2007
Besturk.Net Admin a écrit :
> Hi..
> I am using python with postgresql.
> And i have a query :
>
> aia.execute("SELECT id, w from list")
> links=aia.fetchall()
> print links
>
> and result
> [(1, 5), (2,5).......] (2 million result)
>
> I want to see this result directly as a dictionary:
>
> {1: 5, 2: 5 .....}
>
> How do i select in this format ?
IIRC, postgres' db-api connector (well, at least one of them - I don't
know which one you're using) has a DictCursor. You should find all you
want to know in the relevant doc.
FWIW:
http://www.initd.org/tracker/psycopg/wiki/PsycopgTwoFaq
HTH
More information about the Python-list
mailing list