:return: a `!TypeInfo` object (or subclass) populated with the type
information, `!None` if not found.
- If the connection is async the function will behave as a coroutine and
- the caller will need to `await` on it to get the result::
+ If the connection is async, `!fetch()` will behave as a coroutine and
+ the caller will need to `!await` on it to get the result::
t = await TypeInfo.fetch(aconn, "mytype")
database as a list of the base type.
-For recursive types, Psycopg offers a few `!TypeInfo` subclasses which can be
-used to extract more complete information, such as
-`~psycopg.types.composite.CompositeInfo`, `~psycopg.types.range.RangeInfo`,
-`~psycopg.types.multirange.MultirangeInfo`.
+In order to get information about dynamic PostgreSQL types, Psycopg offers a
+few `!TypeInfo` subclasses, whose `!fetch()` method can extract more complete
+information about the type, such as `~psycopg.types.composite.CompositeInfo`,
+`~psycopg.types.range.RangeInfo`, `~psycopg.types.multirange.MultirangeInfo`,
+`~psycopg.types.enum.EnumInfo`.
`!TypeInfo` objects are collected in `TypesRegistry` instances, which help type
information lookup. Every `~psycopg.adapt.AdaptersMap` exposes its type map on
names as value. The unknown oid is used, so PostgreSQL should be able to
use this string in most contexts (such as an enum or a text field).
+ .. versionchanged:: 3.1
+ In previous version dumping pure enums is not supported and raise a
+ "cannot adapt" error.
+
- Mix-in enums are dumped according to their mix-in type (because a `class
MyIntEnum(int, Enum)` is more specifically an `!int` than an `!Enum`, so
it's dumped by default according to `!int` rules).
- PostgreSQL enums are loaded as Python strings. If you want to load arrays
- of such enums you will have to find their ids using
- `types.TypeInfo.fetch()` and `~types.TypeInfo.register()`.
+ of such enums you will have to find their OIDs using `types.TypeInfo.fetch()`
+ and register them using `~types.TypeInfo.register()`.
- If the enum is registered (using `~types.enum.EnumInfo`\ `!.fetch()` and
`~types.enum.register_enum()`):
- Enums classes, both pure and mixed-in, are dumped by name.
- - The registered PostgreSQL enum is loaded back as the registered Python enum members.
+ - The registered PostgreSQL enum is loaded back as the registered Python
+ enum members.
.. autoclass:: psycopg.types.enum.EnumInfo