Re: Patch: Add parse_type Function
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "David E. Wheeler" <david@justatheory.com>
Cc: Erik Wienhold <ewie@ewie.name>, Jim Jones <jim.jones@uni-muenster.de>, jian he <jian.universality@gmail.com>, Pavel Stehule <pavel.stehule@gmail.com>, Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>, pgsql-hackers@lists.postgresql.org
Date: 2024-03-20T21:23:21Z
Lists: pgsql-hackers
"David E. Wheeler" <david@justatheory.com> writes:
> Thanks, fixed in the attached patch.
Pushed with some editorialization. Mostly, I whacked the
documentation around pretty heavily: we have a convention for what
examples in function descriptions should look like, and this wasn't
it. Not entirely your fault, since some nearby entries in that
table hadn't gotten the word either.
Also, I made a point of adding tests for a corner case that
I initially thought the patch would not get right:
SELECT format_type(to_regtype('bit'), to_regtypemod('bit'));
format_type
-------------
bit(1)
(1 row)
SELECT format_type(to_regtype('"bit"'), to_regtypemod('"bit"'));
format_type
-------------
"bit"
(1 row)
This comes from the comment in format_type():
/*
* bit with typmod -1 is not the same as BIT, which means
* BIT(1) per SQL spec. Report it as the quoted typename so
* that parser will not assign a bogus typmod.
*/
My initial fear was that we'd have to emit NULL for no typmod in order
to round-trip the second case, but it seems to work as-is, so that's good.
I left it emitting -1 for no typmod, and documented that explicitly.
regards, tom lane
Commits
-
Add to_regtypemod function to extract typemod from a string type name.
- 1218ca9956ee 17.0 landed
-
Remove "#ifdef WIN32" guards from src/port/win32*.c
- 09eb633e1baa 17.0 cited