Re: Which Python library - psycopg2 or pygresql?

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Dawid Kuroczko <qnex42(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Which Python library - psycopg2 or pygresql?
Date: 2008-04-15 16:21:19
Message-ID: 4804D5FF.8000403@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2008-04-15 16:38:37 Re: Which Python library - psycopg2 or pygresql?
Previous Message Erik Jones 2008-04-15 15:53:51 Re: Which Python library - psycopg2 or pygresql?