Exploring a Pygresql Backend
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. |