Skip to content

Commit 0347da3

Browse files
author
James William Pye
committed
Implement typio.identify.
1 parent e48f653 commit 0347da3

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

postgresql/driver/pg_type.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,19 @@ def resolve(self,
190190
# Throw warning about type without entry in pg_type?
191191
typio = self.strio
192192
return typio
193+
194+
def identify(self, **identity_mappings):
195+
"""
196+
Explicitly designate the I/O handler for the specified type.
197+
198+
Primarily used in cases involving UDTs.
199+
"""
200+
# get them ordered; we process separately, then recombine.
201+
id = list(identity_mappings.items())
202+
ios = [resolve(x[0]) for x in id]
203+
oids = list(self.database.sys.regtypes([x[1] for x in id]))
204+
205+
self._cache.update([
206+
(oid, io if io.__class__ is tuple else io(oid, self))
207+
for oid, io in zip(oids, ios)
208+
])

postgresql/lib/libsys.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ SELECT
7777
ORDER BY prepared ASC
7878
), ('{}'::text[]))
7979

80+
[regtypes::column]
81+
SELECT (($1::text[])[i])::regtype::oid AS typoid
82+
FROM pg_catalog.generate_series(1, array_upper($1::text[], 1)) AS g(i)
83+
8084
[xact_is_prepared::first]
8185
SELECT TRUE FROM pg_catalog.pg_prepared_xacts WHERE gid::text = $1
8286

postgresql/types/io/contrib_hstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
##
88
# Build the hstore I/O pair for a given typio.
9-
# It primarily need typio for decode and encode.
9+
# It primarily needs typio for decode and encode.
1010
def hstore_factory(oid, typio,
1111
unpack_err = "expected {0} items in hstore, but found {1}".format
1212
):

0 commit comments

Comments
 (0)