Dawid Kuroczko wrote:
So I thought, "lets learn a bit of Python", and I stumbled upon
a choice of these two libraries. Whch would you suggest?
How do they differ?
Well, pygresql seems unmaintained since mid 2006 and the psycopg2 site
is currently and regularly down. Neither inspires confidence.
As to differences, here's one:
Using pygresql
...
result=db.query('select false as booltest')
boolean_result = result.dictresult()[0]['booltest']
print boolean_result
if boolean_result:
print "The result was true"
else:
print "The result was false"
This prints:
f
The result was true
Huh? Seems that pygresql treats boolean as character 't' or 'f', python
evaluates both as 'true' and hilarity ensues. (Yes, I just spent some
"quality time" tracking a bug in a script that used pygresql and had a
loop with a test of a boolean column.)
Using psycopg2:
...
cur.execute('select false as booltest')
boolean_result = cur.fetchall()[0][0]
print boolean_result
if boolean_result:
print "The result was true"
else:
print "The result was false"
This prints:
False
The result was false
There was a brief discussion at the PG users group last week and the
bias was toward psycopg2.
Cheers,
Steve