[DB-SIG] [ANN] pyPgSQL 2.1 released

Gerhard Häring haering_postgresql@gmx.de
Thu, 6 Jun 2002 18:16:54 +0200


* Joseph Wilhelm <jwilhelm@outsourcefinancial.com> [2002-06-06 09:08 -0700]:
> On Thu, 2002-06-06 at 06:30, Andy Dustman wrote:
> <snip> 
> > I'm curious... There are at least two actively maintained PostgreSQL
> > interfaces (three if you count the one that comes with PostgreSQL). I've
> > personally used psycopg a bit lately. What are the advantages and
> > disadvantages of the various interfaces?
> <snip>
> 
> Another bit of curiosity... do either of these interfaces support
> dictionary results? I'm currently using the 'pg' module provided with
> the PostgreSQL distribution primarily for the fact that I have need of
> dictionary results, and pg gladly supplies them. However, if one of
> these is "better", and provides me with dicts, I would love to give it a
> shot.

I'm pretty sure both are way better than PyGreSQL, but I'm probably a
little biased because I once got bitten badly by PyGreSQL bug.

For pyPgSQL, just use the normal fetch methods: these return instances
of PgResultSet, which you can use in three different ways:

cursor.execute("select foo from bar")
res = cursor.fetchone()
print res[0]            # DB-API standard
print res["foo"]        # dictionary-like
print res.foo           # attribute-access 

You can switch off this nonstandard behaviour if you want by setting
PgSQL.fetchReturnsList to 1.

In psycopg, use the various dictfetchXXX functions.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))