1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Add pg_basetype() function to extract a domain's base type.

This SQL-callable function behaves much like our internal utility
function getBaseType(), except it returns NULL rather than failing for
an invalid type OID.  (That behavior is modeled on our experience with
other catalog-inquiry functions such as the ACL checking functions.)
The key advantage over doing a join to pg_type is that it will loop
as needed to find the bottom base type of a nest of domains.

Steve Chavez, reviewed by jian he and others

Discussion: https://postgr.es/m/CAGRrpzZSX8j=MQcbCSEisFA=ic=K3bknVfnFjAv1diVJxFHJvg@mail.gmail.com
This commit is contained in:
Tom Lane
2024-03-30 13:57:19 -04:00
parent ecf741cfae
commit b154d8a6d0
6 changed files with 110 additions and 1 deletions

View File

@ -25129,6 +25129,30 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_basetype</primary>
</indexterm>
<function>pg_basetype</function> ( <type>regtype</type> )
<returnvalue>regtype</returnvalue>
</para>
<para>
Returns the OID of the base type of a domain identified by its
type OID. If the argument is the OID of a non-domain type,
returns the argument as-is. Returns NULL if the argument is
not a valid type OID. If there's a chain of domain dependencies,
it will recurse until finding the base type.
</para>
<para>
Assuming <literal>CREATE DOMAIN mytext AS text</literal>:
</para>
<para>
<literal>pg_basetype('mytext'::regtype)</literal>
<returnvalue>text</returnvalue>
</para></entry>
</row>
<row>
<entry id="pg-char-to-encoding" role="func_table_entry"><para role="func_signature">
<indexterm>