mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-14 16:20:33 +03:00
hstore registration doesn't fail if typarray column not available.
This commit is contained in:
parent
163cf5bfb4
commit
94348bfb78
|
@ -655,6 +655,7 @@ class HstoreAdapter(object):
|
||||||
|
|
||||||
parse_unicode = classmethod(parse_unicode)
|
parse_unicode = classmethod(parse_unicode)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def get_oids(self, conn_or_curs):
|
def get_oids(self, conn_or_curs):
|
||||||
"""Return the oid of the hstore and hstore[] types.
|
"""Return the oid of the hstore and hstore[] types.
|
||||||
|
|
||||||
|
@ -670,13 +671,16 @@ class HstoreAdapter(object):
|
||||||
# Store the transaction status of the connection to revert it after use
|
# Store the transaction status of the connection to revert it after use
|
||||||
conn_status = conn.status
|
conn_status = conn.status
|
||||||
|
|
||||||
|
# column typarray not available before PG 8.3
|
||||||
|
typarray = conn.server_version >= 80300 and "typarray" or "NULL"
|
||||||
|
|
||||||
# get the oid for the hstore
|
# get the oid for the hstore
|
||||||
curs.execute("""\
|
curs.execute("""\
|
||||||
SELECT t.oid, typarray
|
SELECT t.oid, %s
|
||||||
FROM pg_type t JOIN pg_namespace ns
|
FROM pg_type t JOIN pg_namespace ns
|
||||||
ON typnamespace = ns.oid
|
ON typnamespace = ns.oid
|
||||||
WHERE typname = 'hstore' and nspname = 'public';
|
WHERE typname = 'hstore' and nspname = 'public';
|
||||||
""")
|
""" % typarray)
|
||||||
oids = curs.fetchone()
|
oids = curs.fetchone()
|
||||||
|
|
||||||
# revert the status of the connection as before the command
|
# revert the status of the connection as before the command
|
||||||
|
@ -686,8 +690,6 @@ WHERE typname = 'hstore' and nspname = 'public';
|
||||||
|
|
||||||
return oids
|
return oids
|
||||||
|
|
||||||
get_oids = classmethod(get_oids)
|
|
||||||
|
|
||||||
def register_hstore(conn_or_curs, globally=False, unicode=False):
|
def register_hstore(conn_or_curs, globally=False, unicode=False):
|
||||||
"""Register adapter and typecaster for `dict`\-\ |hstore| conversions.
|
"""Register adapter and typecaster for `dict`\-\ |hstore| conversions.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user