diff --git a/doc/src/extras.rst b/doc/src/extras.rst index 4fbf051e..ae4e940f 100644 --- a/doc/src/extras.rst +++ b/doc/src/extras.rst @@ -247,6 +247,12 @@ requires no adapter registration. The name of the PostgreSQL type. + .. attribute:: schema + + The schema where the type is defined. + + .. versionadded:: 2.4.6 + .. attribute:: oid The oid of the PostgreSQL type. diff --git a/lib/extras.py b/lib/extras.py index 65f2bb64..7318253b 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -803,8 +803,9 @@ class CompositeCaster(object): using an :ref:`asynchronous connections `). """ - def __init__(self, name, oid, attrs, array_oid=None): + def __init__(self, name, oid, attrs, array_oid=None, schema=None): self.name = name + self.schema = schema self.oid = oid self.array_oid = array_oid @@ -926,7 +927,7 @@ ORDER BY attnum; type_attrs = [ (r[2], r[3]) for r in recs ] return self(tname, type_oid, type_attrs, - array_oid=array_oid) + array_oid=array_oid, schema=schema) def register_composite(name, conn_or_curs, globally=False, factory=None): """Register a typecaster to convert a composite type into a tuple. diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py index b8f72419..f5a60818 100755 --- a/tests/test_types_extras.py +++ b/tests/test_types_extras.py @@ -532,6 +532,7 @@ class AdaptTypeTestCase(unittest.TestCase): t = psycopg2.extras.register_composite("type_isd", self.conn) self.assertEqual(t.name, 'type_isd') + self.assertEqual(t.schema, 'public') self.assertEqual(t.oid, oid) self.assert_(issubclass(t.type, tuple)) self.assertEqual(t.attnames, ['anint', 'astring', 'adate']) @@ -655,6 +656,7 @@ class AdaptTypeTestCase(unittest.TestCase): [("a", "integer"), ("b", "integer")]) t = psycopg2.extras.register_composite( "typens.typens_ii", self.conn) + self.assertEqual(t.schema, 'typens') curs.execute("select (4,8)::typens.typens_ii") self.assertEqual(curs.fetchone()[0], (4,8))