Exploring a Pygresql Backend

April 16, 2008

I was running into an issue with Psycopg2 and Decimal where you couldn't add a Decimal value on your model object to a regular non-model-object Decimal value [1] [2].

While I was waiting for the initd.org site to come back up so I could download the latest psycopg2 release to fix the problem, I decided to see how hard it would be integrate PyGreSQL into the backend system.

I decided to use the pgdb API as it's DB-API 2.0 compliant. It turns out that in about an hour I was able to digest the django.db.backend code and get a postgresql_pgdb backend working.

Most of my efforts leveraged the existing postgres backends provided by Django, so I really didn't generate a lot of new code.

Where I ran into problems was with the typing provided by the pgdb package. The database type NUMERIC is returned as a float and dates and times are returned as strings.

Still waiting for the initd site to come back up, I went ahead and poked my nose into the pgdb.py module and found it pretty easy to enhance it's casting of types (it doesn't support type extensions like PsycoPG). By the time initd came back up I had the pgdb module returning decimals, datetimes, dates, and times.

All this was pretty exciting, but once I got a hold of the latest Psycopg2 release, a quick download, build, and install fixed my original problem. And so the PyGreSQL code now sits as 'psuedo-abandoned' in my /usr/local/src/django/trunk directory.

The question left in my head is the following: Would a PyGreSQL backend be a worthwhile endeavor? Since it was just a hop, skip, and a jump to get the thing 80% functional (based on the 80/20 rule), would it be helpful to have another Postgres backend?

I'm a relative newbie to the Python world, so I don't know the cultural status of PyGreSQL vs. PsycoPG, and whether or not PyGreSQL is a serious contender for Postgres connectivity market share...

Anyway, I thought I would share this experience as I found it enlightening. Thanks for reading...

doug.

Post Script:

I ran into this issue while working on a client website who sells rolex watches. He asked for a little link love. :-)

[1]django-users discussion: unsupported operand type(s) for *: 'Decimal' and 'Decimal'
[2]django-developers discussion: DecimalField and 'decimal' module.

2 Comments

  • Jonathan Ballet   April 17, 2008 at 4:27 a.m.

    There was a recent thread on pgsql-general [1], asking which Python library is recommanded. Not very informative, but psycopg2 seems to be the default choice now.

    [1] : http://archives.postgresql.org/pgsql-general/2008-04/msg00763.php

  • Peter   April 17, 2008 at 12:06 p.m.

    Would it be worth while? Of course. There are some people who complain that that Psycopg2 isn't up to snuff. In fact David Cramer was complaining about it in the django IRC chat the other day. I have used PyGreSQL for huge projects in the past and never really touched Psycopg2 until I started with Django a year ago.

    Couldn't hurt to have an alternative. I'd be interested in testing your code myself. Is it available for download?

    Peter
    pjs[at]petersanchez[dot]com

Post a Comment




Archives

  • No articles found.