from the context, but this may fail in some contexts and may require a
cast (e.g. specifying :samp:`%s::{type}` for its placeholder).
- You can use the `psycopg.adapters`\ ``.``\ `~psycopg.adapt.AdaptersMap.types`
- registry to find the OID of builtin types, and you can use
- `~psycopg.types.TypeInfo` to extend the registry to custom types.
+ You can use the `psycopg.adapters`\ ``.``\
+ `~psycopg.adapt.AdaptersMap.types` registry to find the OID of builtin
+ types, and you can use `~psycopg.types.TypeInfo` to extend the
+ registry to custom types.
.. automethod:: get_key
.. automethod:: upgrade
The global registry, from which the others inherit from, is available as
`psycopg.adapters`\ ``.types``.
+ .. automethod:: __getitem__
+
+ .. code:: python
+
+ >>> import psycopg
+
+ >>> psycopg.adapters.types["text"]
+ <TypeInfo: text (oid: 25, array oid: 1009)>
+
+ >>> psycopg.adapters.types[23]
+ <TypeInfo: int4 (oid: 23, array oid: 1007)>
+
+ .. automethod:: get
+
+ .. automethod:: get_oid
+
+ .. code:: python
+
+ >>> psycopg.adapters.types.get_oid("text[]")
+ 1009
.. _numeric-wrappers:
"""
Return info about a type, specified by name or oid
- The type name or oid may refer to the array too.
+ :param key: the name or oid of the type to look for.
Raise KeyError if not found.
"""
"""
Return info about a type, specified by name or oid
- The type name or oid may refer to the array too.
+ :param key: the name or oid of the type to look for.
- Return None if not found.
+ Unlike `__getitem__`, return None if not found.
"""
try:
return self[key]
"""
Return the oid of a PostgreSQL type by name.
- Return the array oid if the type ends with "[]"
+ :param key: the name of the type to look for.
+
+ Return the array oid if the type ends with "``[]``"
Raise KeyError if the name is unknown.
"""