Don't crash on null pstate in coerce_record_to_complex(). Since commit 913bbd88d, this case is reachable if a SQL-language function returns a whole-row Var of type RECORD when its declared output type is a named composite type. We'd need the original ParseState to find out what the Var's columns are, but we don't have that structure at hand anymore. This didn't work before 913bbd88d either, but you got a slightly off-point error message instead of a crash.
Given that this has never worked and there's been no field complaints about that before now, it doesn't seem worth doing major work to fix this. Let's just ensure that we throw a helpful error explaining what to do to work around the limitation. (The workaround actually reaches this same code, but does so while we still have the ParseState.) While at it, update various badly-obsolete comments about what coerce_type() uses its pstate argument for. Bug: #19906 Reported-by: Boris Murasov <[email protected]> Author: Tom Lane <[email protected]> Reviewed-by: Ayush Tiwari <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5c9da8b0e226e6d269e443b166850ec739788e4f Modified Files -------------- src/backend/parser/parse_coerce.c | 48 ++++++++++++++++++++------------ src/backend/parser/parse_expr.c | 4 +-- src/backend/parser/parse_func.c | 3 +- src/test/regress/expected/rangefuncs.out | 9 +++++- src/test/regress/sql/rangefuncs.sql | 7 ++++- 5 files changed, 46 insertions(+), 25 deletions(-)
