diff --git a/asyncpg/connection.py b/asyncpg/connection.py index 3a86466c..ba8be2ef 100644 --- a/asyncpg/connection.py +++ b/asyncpg/connection.py @@ -534,26 +534,18 @@ async def _introspect_types(self, typeoids, timeout): return result async def _introspect_type(self, typename, schema): - if ( - schema == 'pg_catalog' - and typename.lower() in protocol.BUILTIN_TYPE_NAME_MAP - ): - typeoid = protocol.BUILTIN_TYPE_NAME_MAP[typename.lower()] - rows = await self._execute( - introspection.TYPE_BY_OID, - [typeoid], - limit=0, - timeout=None, - ignore_custom_codec=True, - ) - else: - rows = await self._execute( - introspection.TYPE_BY_NAME, - [typename, schema], - limit=1, - timeout=None, - ignore_custom_codec=True, - ) + if schema == 'pg_catalog' and not typename.endswith("[]"): + typeoid = protocol.BUILTIN_TYPE_NAME_MAP.get(typename.lower()) + if typeoid is not None: + return introspection.TypeRecord((typeoid, None, b"b")) + + rows = await self._execute( + introspection.TYPE_BY_NAME, + [typename, schema], + limit=1, + timeout=None, + ignore_custom_codec=True, + ) if not rows: raise ValueError( diff --git a/asyncpg/introspection.py b/asyncpg/introspection.py index 641cf700..c3b4e60c 100644 --- a/asyncpg/introspection.py +++ b/asyncpg/introspection.py @@ -7,10 +7,12 @@ from __future__ import annotations import typing +from .protocol.protocol import _create_record # type: ignore if typing.TYPE_CHECKING: from . import protocol + _TYPEINFO_13: typing.Final = '''\ ( SELECT @@ -267,16 +269,12 @@ ''' -TYPE_BY_OID = '''\ -SELECT - t.oid, - t.typelem AS elemtype, - t.typtype AS kind -FROM - pg_catalog.pg_type AS t -WHERE - t.oid = $1 -''' +def TypeRecord( + rec: typing.Tuple[int, typing.Optional[int], bytes], +) -> protocol.Record: + assert len(rec) == 3 + return _create_record( # type: ignore + {"oid": 0, "elemtype": 1, "kind": 2}, rec) # 'b' for a base type, 'd' for a domain, 'e' for enum.