psycopg2 and Binary

69 views
Skip to first unread message

Jonathan S

unread,
Sep 7, 2011, 11:46:41 AM9/7/11
to Django users
Hi django users,

Not sure whether this is a bug or configuration issue.

I have a postgres with postgis setup. It works perfect on a postgres
8.4 machine, but it doesn't on a postgres 9.1 machine.

The problem is when constructing GIS queries.
django.contrib.gis relies on psycopg2.Binary for encoding binary data
like polygons.

When connected to the postgres 8.4 machine, output is double-quoted,
like \\000\\000, but when connected to the 9.1 machine, the output of
Binary is only single quoted, like \000\000. This causes of course
encoding issues, because it conflicts with the null-termination.

Any help?

Thanks,
Jonathan

Jonathan S

unread,
Sep 7, 2011, 11:54:32 AM9/7/11
to Django users
So, it works if I patch
django.contrib.gis.db.backends.postgis.adapter. But that's obviously
*not* the way to go...


class PostGISAdapter(object):
...
def getquoted(self):
"Returns a properly quoted string for use in PostgreSQL/
PostGIS."
# Want to use WKB, so wrap with psycopg2 Binary() to quote
properly.
return 'ST_GeomFromEWKB(E%s)' %
unicode(Binary(self.ewkb)).replace('\\', '\\\\')
Reply all
Reply to author
Forward
0 new messages