Re: Patch: Add parse_type Function
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To: Jim Jones <jim.jones@uni-muenster.de>
Cc: "David E. Wheeler" <david@justatheory.com>,
pgsql-hackers@lists.postgresql.org, Pavel Stehule
<pavel.stehule@gmail.com>
Date: 2024-02-05T14:32:16Z
Lists: pgsql-hackers
Jim Jones <jim.jones@uni-muenster.de> writes: > 1) The function causes a crash when called with a NULL parameter: > > SELECT * FROM parse_type(NULL); > server closed the connection unexpectedly > This probably means the server terminated abnormally > before or while processing the request. > The connection to the server was lost. Attempting reset: Failed. > The connection to the server was lost. Attempting reset: Failed. > > You have to check it in the beginning of function and either return an > error message or just NULL, e.g > > if (PG_ARGISNULL(0)) > PG_RETURN_NULL(); Instead of handling this in the function body, the function should be declared as strict. This is in fact the default in pg_proc.h, /* strict with respect to NULLs? */ bool proisstrict BKI_DEFAULT(t); so removing the explicit proisstrict => 'f' from the pg_proc.dat entry will fix it with no additional code. > 2) Add a function call with NULL in the regression tests > > SELECT * FROM parse_type(NULL); > > 3) Add the expected behaviour of calling the function with NULL in the > docs (error message or null) Once the function is declared strict, I don't think either of these is necessary: function strictness is tested elsewhere, and it's the default behaviour. The only functions that explicitly say they return NULL on NULL inputs are quote_literal (because you might expect it to return the string 'NULL', but there's qoute_nullable for that) and xmlexists (which I don't see any particular reason for). - ilmari
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