Re: Add pg_basetype() function to obtain a DOMAIN base type
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: Alexander Korotkov <aekorotkov@gmail.com>,
Tomas Vondra <tomas.vondra@enterprisedb.com>,
John Naylor <johncnaylorls@gmail.com>,
Steve Chavez <steve@supabase.io>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-03-28T20:47:48Z
Lists: pgsql-hackers
Attachments
- v7-0001-Add-pg_basetype-regtype-function-to-return-the-ba.patch (text/x-diff) patch v7-0001
jian he <jian.universality@gmail.com> 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 catalog inspection functions like this to be forgiving of bad input. Otherwise, your query can blow up in unexpected ways due to race conditions (ie somebody just dropped the type you are interested in). 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. Either way though, we can't use getBaseType as-is. We could imagine extending that function to support a "noerror"-like flag, but I believe it's already a hot-spot and I'd rather not complicate it further. So what I suggest doing is just duplicating the code; there's not very much of it. I did a little polishing of the docs and test cases too, ending with the v7 attached. I think this is about ready to go unless there are objections to the definition. Not sure what I think about your 0002 proposal to extend \dD with this. Aside from the server-version-compatibility problem, I think it's about 90% redundant because \dD already shows the immediate base type. The new column would only be different in the case of nested domains, which I think are not common. \dD's output is already pretty wide, so on the whole I'm inclined to leave it alone. regards, tom lane
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add pg_basetype() function to extract a domain's base type.
- b154d8a6d0e5 17.0 landed