Re: Which Python library - psycopg2 or pygresql? - Mailing list pgsql-general

From Steve Crawford
Subject Re: Which Python library - psycopg2 or pygresql?
Date
Msg-id 4804D5FF.8000403@pinpointresearch.com
Whole thread Raw
In response to Which Python library - psycopg2 or pygresql?  ("Dawid Kuroczko" <qnex42@gmail.com>)
Responses Re: Which Python library - psycopg2 or pygresql?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Erik Jones
Date:
Subject: Re: Which Python library - psycopg2 or pygresql?
Next
From: "Filip Rembiałkowski"
Date:
Subject: Re: Which Python library - psycopg2 or pygresql?