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

2024-03-30 Thread Tom Lane
I wrote: > A fairly common solution to that is to return NULL for bad input, > but in this case we could just have it return the OID unchanged. After sleeping on it, I concluded that was a bad idea and we'd be best off returning NULL for invalid type OIDs. So this is just about back to Steve's

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

2024-03-28 Thread Tom Lane
jian he writes: > 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 Yeah, that's not really OK. You could say it's fine for bogus input, but we've found over the years that it's better for

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

2024-03-27 Thread Tom Lane
jian he writes: > I noticed psql \dD didn't return the basetype of a domain. > one of the usage of this feature would be in psql \dD. Your 0002 will cause \dD to fail entirely against an older server. I'm not necessarily against adding this info, but you can't just ignore the expectations for

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

2024-03-27 Thread jian he
On Thu, Mar 21, 2024 at 10:34 AM jian he wrote: > > On Mon, Mar 18, 2024 at 11:43 PM Tom Lane wrote: > > > > Alexander Korotkov writes: > > > On Mon, Mar 18, 2024 at 2:01 AM jian he > > > wrote: > > >> ` > > >> Datum > > >> pg_basetype(PG_FUNCTION_ARGS) > > >> { > > >> Oid oid; > > >> >

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

2024-03-20 Thread jian he
On Mon, Mar 18, 2024 at 11:43 PM Tom Lane wrote: > > Alexander Korotkov writes: > > On Mon, Mar 18, 2024 at 2:01 AM jian he wrote: > >> ` > >> Datum > >> pg_basetype(PG_FUNCTION_ARGS) > >> { > >> Oid oid; > >> > >> oid = get_fn_expr_argtype(fcinfo->flinfo, 0); > >>

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

2024-03-18 Thread Tom Lane
Alexander Korotkov writes: > On Mon, Mar 18, 2024 at 2:01 AM jian he 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

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

2024-03-18 Thread Alexander Korotkov
On Mon, Mar 18, 2024 at 2:01 AM jian he wrote: > > looking at it again. > I found out we can just simply do > ` > Datum > pg_basetype(PG_FUNCTION_ARGS) > { > Oid oid; > > oid = get_fn_expr_argtype(fcinfo->flinfo, 0); > PG_RETURN_OID(getBaseType(oid)); > } > ` > > if the type is not a domain,

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

2024-03-17 Thread jian he
looking at it again. I found out we can just simply do ` Datum pg_basetype(PG_FUNCTION_ARGS) { Oid oid; oid = get_fn_expr_argtype(fcinfo->flinfo, 0); PG_RETURN_OID(getBaseType(oid)); } ` if the type is not a domain, work the same as pg_typeof. if the type is domain, pg_typeof return as is,

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

2024-02-18 Thread jian he
On Sun, Feb 18, 2024 at 7:29 AM Tomas Vondra wrote: > > > Also, now that I looked at the v2 patch again, I see it only really > tweaked the pg_proc.dat entry, but the code still does PG_GETARG_OID (so > the "any" bit is not really correct). > PG_GETARG_OID part indeed is wrong. so I change to

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

2024-02-17 Thread jian he
On Sun, Feb 18, 2024 at 2:49 AM Tomas Vondra wrote: > > An alternative approach would be modifying pg_typeof() to optionally > determine the base type, depending on a new argument which would default > to "false" (i.e. the current behavior). > > So you'd do > > SELECT pg_typeof(x); > > or > >

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

2024-02-17 Thread Tom Lane
Tomas Vondra writes: > On 2/17/24 20:20, Tom Lane wrote: >> I don't have an immediate proposal for exactly what to call such a >> function, but naming it by analogy to pg_typeof would be questionable. > Are you objecting to the pg_basetypeof() name, or just to it accepting > "any" argument? I

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

2024-02-17 Thread Tomas Vondra
On 2/17/24 20:20, Tom Lane wrote: > Tomas Vondra writes: >> On 2/17/24 01:57, jian he wrote: >>> On Sat, Feb 17, 2024 at 2:16 AM Tomas Vondra >>> wrote: 1) We already have pg_typeof() function, so maybe we should use a similar naming convention pg_basetypeof()? > >>> I am ok with

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

2024-02-17 Thread Tom Lane
Tomas Vondra writes: > On 2/17/24 01:57, jian he wrote: >> On Sat, Feb 17, 2024 at 2:16 AM Tomas Vondra >> wrote: >>> 1) We already have pg_typeof() function, so maybe we should use a >>> similar naming convention pg_basetypeof()? >> I am ok with pg_basetypeof. > An alternative approach would

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

2024-02-17 Thread Tomas Vondra
On 2/17/24 01:57, jian he wrote: > On Sat, Feb 17, 2024 at 2:16 AM Tomas Vondra > wrote: >> >> Hi, >> >> On 1/2/24 01:00, jian he wrote: >>> On Mon, Dec 4, 2023 at 5:11 PM John Naylor wrote: On Thu, Sep 28, 2023 at 12:22 AM Alexander Korotkov wrote: > The one thing

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

2024-02-16 Thread jian he
On Sat, Feb 17, 2024 at 2:16 AM Tomas Vondra wrote: > > Hi, > > On 1/2/24 01:00, jian he wrote: > > On Mon, Dec 4, 2023 at 5:11 PM John Naylor wrote: > >> > >> On Thu, Sep 28, 2023 at 12:22 AM Alexander Korotkov > >> wrote: > >>> The one thing triggering my perfectionism is that the patch does

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

2024-02-16 Thread Tomas Vondra
Hi, On 1/2/24 01:00, jian he wrote: > On Mon, Dec 4, 2023 at 5:11 PM John Naylor wrote: >> >> On Thu, Sep 28, 2023 at 12:22 AM Alexander Korotkov >> wrote: >>> The one thing triggering my perfectionism is that the patch does two >>> syscache lookups instead of one. >> >> For an admin function

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

2024-01-01 Thread jian he
On Mon, Dec 4, 2023 at 5:11 PM John Naylor wrote: > > On Thu, Sep 28, 2023 at 12:22 AM Alexander Korotkov > wrote: > > The one thing triggering my perfectionism is that the patch does two > > syscache lookups instead of one. > > For an admin function used interactively, I'm not sure why that >

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

2023-12-04 Thread John Naylor
On Thu, Sep 28, 2023 at 12:22 AM Alexander Korotkov wrote: > The one thing triggering my perfectionism is that the patch does two > syscache lookups instead of one. For an admin function used interactively, I'm not sure why that matters? Or do you see another use case?

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

2023-11-17 Thread jian he
On Thu, Sep 28, 2023 at 11:56 AM Alexander Korotkov wrote: > > The one thing triggering my perfectionism is that the patch does two > syscache lookups instead of one. In order to fit into one syscache > lookup we could add "bool missing_ok" argument to > getBaseTypeAndTypmod(). However,

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

2023-09-27 Thread Alexander Korotkov
Hi, Steve! On Tue, Sep 19, 2023 at 8:36 PM Steve Chavez wrote: > > Just to give a data point for the need of this function: > > https://dba.stackexchange.com/questions/231879/how-to-get-the-basetype-of-a-domain-in-pg-type > > This is also a common use case for services/extensions that require

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

2023-09-19 Thread Steve Chavez
Just to give a data point for the need of this function: https://dba.stackexchange.com/questions/231879/how-to-get-the-basetype-of-a-domain-in-pg-type This is also a common use case for services/extensions that require postgres metadata for their correct functioning, like postgREST or

Add pg_basetype() function to obtain a DOMAIN base type

2023-09-08 Thread Steve Chavez
Hello hackers, Currently obtaining the base type of a domain involves a somewhat long recursive query. Consider: ``` create domain mytext as text; create domain mytext_child_1 as mytext; create domain mytext_child_2 as mytext_child_1; ``` To get `mytext_child_2` base type we can do: ``` WITH