Ticket #461 (enhancement) - Support use of pypgsql instead of psycopg

5 views
Skip to first unread message

Carlo C8E Miron

unread,
Sep 5, 2005, 10:49:36 AM9/5/05
to tristan...@gmail.com, django...@googlegroups.com
Hi,

> I do not see any information on the generally excellent Django website about alternatives to psychopg as a PostGreSQL connector. I have been having some non-Django problems getting psychopg to work so it would be nice if there was another option such as pypgsql.

Wich problems did you have? psycopg rocks :-D
If it was only a licence issue, please see below.

> While researching I did find this page: http://blog.vrplumber.com/968 so it seems that I am not the only one with this request.

Thank you for the signalation. I've submitted it to Federico (the main
psycopg author) and he reply with a comment on the page.

I've discussed this issue with him some time ago. The reason why
psycopg is GPL'd is only to avoid that non free drivers will be
derived from it. I can guarantee that nobody in initd will pursue no
one for *using* it in non-GPL projects.

We recently rewrote the license of psycopg2 in order to explain that. See:

http://initd.org/tracker/psycopg/file/psycopg2/trunk/LICENSE

This is the intended behavior of the license also for psycopg1, even
if not explicitly stated. Or, if that make you feel better, you can
use psycopg2 with Django with *one* of the two trivial patches

1. using psycopg2 -> psycopg1 compatiblity layer
{{{
Index: django/trunk/django/core/db/backends/postgresql.py
===================================================================
--- django/trunk/django/core/db/backends/postgresql.py (revision 618)
+++ django/trunk/django/core/db/backends/postgresql.py (local copy)
@@ -5,7 +5,7 @@
"""

from django.core.db import base, typecasts
-import psycopg as Database
+import psycopg2.psycopg1 as Database

DatabaseError = Database.DatabaseError

}}}
2. using either psycopg1 or psycopg2 full power, at your choice (untested)
{{{
Index: django/trunk/django/core/db/backends/postgresql.py
===================================================================
--- django/trunk/django/core/db/backends/postgresql.py (revision 618)
+++ django/trunk/django/core/db/backends/postgresql.py (local copy)
@@ -5,7 +5,12 @@
"""

from django.core.db import base, typecasts
-import psycopg as Database
+try:
+ import psycopg2 as Database
+ from psycopg2.extensions import register_type
+except ImportError:
+ import psycopg as Database
+ from psycopg import register_type

DatabaseError = Database.DatabaseError

@@ -115,13 +120,10 @@
# Register these custom typecasts, because Django expects dates/times to be
# in Python's native (standard-library) datetime/time format, whereas psycopg
# use mx.DateTime by default.
-try:
- Database.register_type(Database.new_type((1082,), "DATE",
typecasts.typecast_date))
-except AttributeError:
- raise Exception, "You appear to be using psycopg version 2, which
isn't supported yet, because it's still in beta. Use psycopg version 1
instead: http://initd.org/projects/psycopg1"
-Database.register_type(Database.new_type((1083,1266), "TIME",
typecasts.typecast_time))
-Database.register_type(Database.new_type((1114,1184), "TIMESTAMP",
typecasts.typecast_timestamp))
-Database.register_type(Database.new_type((16,), "BOOLEAN",
typecasts.typecast_boolean))
+register_type(Database.new_type((1082,), "DATE", typecasts.typecast_date))
+register_type(Database.new_type((1083,1266), "TIME", typecasts.typecast_time))
+register_type(Database.new_type((1114,1184), "TIMESTAMP",
typecasts.typecast_timestamp))
+register_type(Database.new_type((16,), "BOOLEAN", typecasts.typecast_boolean))

OPERATOR_MAPPING = {
'exact': '=',
}}}

HTH, HAND

(c)

--
Carlo C8E Miron, ICQ #26429731
--
Disclaimer:
If I receive a message from you, you are agreeing that:
1. I am by definition, "the intended recipient".
2. All information in the email is mine to do with as I see fit and
make such financial profit, political mileage, or good joke as it
lends itself to. In particular, I may quote it on USENET or the WWW.
3. I may take the contents as representing the views of your company.
4. This overrides any disclaimer or statement of confidentiality that
may be included on your message.

Carlo C8E Miron

unread,
Sep 8, 2005, 1:02:08 PM9/8/05
to tristan...@gmail.com, django...@googlegroups.com
2005/9/5, Tristan Lawrence <tristan...@gmail.com>:
> Well, my first problem was that blastwave.org does not have a psycopg package
> for Solaris. But then I did a source install only to have it keep coredumping
> on me :(

hi tristan
sorry for the late reply.
have you seen the following post (and the several others thread
retourned by googling for "psycopg solaris site:lists.initd.org")?
maybe something similar'll apply fine to you too...

http://lists.initd.org/pipermail/psycopg/2003-March/001920.html

(there are aother stuff, no time to check now, sorry...)

HTH, and let me know

Carlo C8E Miron

unread,
Sep 9, 2005, 4:23:23 AM9/9/05
to Federico Di Gregorio, django...@googlegroups.com
Forwarding to Federico and to list for completeness (maybe also for
furter suggestions.. ;)

---------- Forwarded message ----------
From: Tristan Lawrence <tristan...@gmail.com>
Date: 9-set-2005 3.01
Subject: Re: Ticket #461 (enhancement) - Support use of pypgsql
instead of psycopg
To: Carlo C8E Miron <carlo...@gmail.com>


Hi Carlo

I am still not on the django users list, so I am replying just to you.
This is really an issue for the psycopg list anyway-thanks for
pointing it out. I did some Google searches but was not looking
specifically at the initd server.

The fix from the message you sent me the URL for did not help.
I updated the ticket at:

http://code.djangoproject.com/ticket/461

with all of the gory details.

I also did the Google search you recommended and it looks like
this gentleman:

http://lists.initd.org/pipermail/psycopg/2005-March/003395.html

had the exact problem I did. I did not see any responses to his
email so I am going to try to get on the list and send out an email
describing my issue.

Thanks again for your help.

Tristan
Reply all
Reply to author
Forward
0 new messages