From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Alexander Korotkov <aekorotkov(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-28 02:54:08 |
Message-ID: | CACJufxEF3V0ef417Lna3jALgQU11tEGAc+eKt-fyujjGmwbZ8Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Mar 21, 2024 at 10:34 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> On Mon, Mar 18, 2024 at 11:43 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >
> > 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))
> >
>
> trying to do it this way.
> not sure the following error message is expected.
>
> SELECT pg_basetype(-1);
> ERROR: cache lookup failed for type 4294967295
I think the error message should be fine.
even though
`select '-1'::oid::regtype;` return 4294967295.
I noticed psql \dD didn't return the basetype of a domain.
one of the usage of this feature would be in psql \dD.
now we can:
\dD mytext_child_2
List of domains
Schema | Name | Type | Basetype | Collation |
Nullable | Default | Check
--------+----------------+----------------+----------+-----------+----------+---------+-------
public | mytext_child_2 | mytext_child_1 | text | |
| |
(1 row)
Attachment | Content-Type | Size |
---|---|---|
v6-0002-make-psql-dD-displays-the-domain-s-basetype.patch | text/x-patch | 1.5 KB |
v6-0001-Add-pg_basetype-regtype-function-to-return-the-ba.patch | text/x-patch | 5.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2024-03-28 02:56:35 | Re: Properly pathify the union planner |
Previous Message | Richard Guo | 2024-03-28 02:48:03 | Re: Properly pathify the union planner |