psycopg2 and Binary

Showing 1-2 of 2 messages
psycopg2 and Binary Jonathan S 9/7/11 8:46 AM
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?

Re: psycopg2 and Binary Jonathan S 9/7/11 8:54 AM
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/
        # Want to use WKB, so wrap with psycopg2 Binary() to quote
        return 'ST_GeomFromEWKB(E%s)' %
unicode(Binary(self.ewkb)).replace('\\', '\\\\')