Re: Add pg_basetype() function to obtain a DOMAIN base type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, John Naylor <johncnaylorls(at)gmail(dot)com>, Steve Chavez <steve(at)supabase(dot)io>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add pg_basetype() function to obtain a DOMAIN base type
Date: 2024-03-18 15:43:51
Message-ID: 3570987.1710776631@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alexander Korotkov <aekorotkov(at)gmail(dot)com> writes:
> On Mon, Mar 18, 2024 at 2:01 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>> `
>> Datum
>> pg_basetype(PG_FUNCTION_ARGS)
>> {
>> Oid oid;
>>
>> oid = get_fn_expr_argtype(fcinfo->flinfo, 0);
>> PG_RETURN_OID(getBaseType(oid));
>> }
>> `

> Looks good to me. But should it be named pg_basetypeof()?

I still don't like this approach. It forces the function to be
used in a particular way that's highly redundant with pg_typeof.
I think we'd be better off with

pg_basetype(PG_FUNCTION_ARGS)
{
Oid typid = PG_GETARG_OID(0);

PG_RETURN_OID(getBaseType(typid));
}

The use-case that the other definition handles would be implemented
like

pg_basetype(pg_typeof(expression))

but there are other use-cases. For example, if you want to know
the base types of the columns of a table, you could do something
like

select attname, pg_basetype(atttypid) from pg_attribute
where attrelid = 'foo'::regclass order by attnum;

but that functionality is simply not available with the other
definition.

Perhaps there's an argument for providing both things, but that
feels like overkill to me. I doubt that pg_basetype(pg_typeof())
is going to be so common as to need a shorthand.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-03-18 15:44:20 Re: Possibility to disable `ALTER SYSTEM`
Previous Message Magnus Hagander 2024-03-18 15:34:26 Re: Possibility to disable `ALTER SYSTEM`