]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: extend on the type info note
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 1 Jun 2024 11:05:54 +0000 (13:05 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 1 Jun 2024 11:07:12 +0000 (13:07 +0200)
docs/advanced/adapt.rst

index 4323b07de5f42528fc7e3d83a11248437c4ee186..66a8edbcf49c4d6b8788a55cedd9fdb14fc7abb1 100644 (file)
@@ -119,10 +119,31 @@ you only need to implement the `~psycopg.abc.Dumper.dump()` method::
     >>> conn.execute("SELECT xpath('//title/text()', %s)", [elem]).fetchone()[0]
     ['Manual']
 
-Note that it is possible to use a `~psycopg.types.TypesRegistry`, exposed by
-any `~psycopg.abc.AdaptContext`, to obtain information on builtin types, or
-extension types if they have been registered on that context using the
-`~psycopg.types.TypeInfo`\.\ `~psycopg.types.TypeInfo.register()` method.
+.. note::
+
+    You can use a `~psycopg.types.TypesRegistry`, exposed by
+    any `~psycopg.abc.AdaptContext`, to obtain information on builtin types, in
+    the form of a `TypeInfo` object::
+
+        # Global types registry
+        >>> psycopg.adapters.types["text"]
+        <TypeInfo: text (oid: 25, array oid: 1009)>
+
+        # Types registry on a connection
+        >>> conn.adapters.types["integer"]
+        <TypeInfo: int4 (oid: 23, array oid: 1007)>
+
+    The same method can be used to get information about extension types if
+    they have been registered on that context using the
+    `~psycopg.types.TypeInfo`\.\ `~psycopg.types.TypeInfo.register()` method::
+
+        >>> (t := psycopg.types.TypeInfo.fetch(conn, "hstore"))
+        <TypeInfo: hstore (oid: 770082, array oid: 770087)>
+
+        >>> t.register()  # globally
+
+        >>> psycopg.adapters.types["hstore"]
+        <TypeInfo: hstore (oid: 770082, array oid: 770087)>
 
 
 .. _adapt-example-float: