]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix handling of polymorphic output arguments for procedures.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 May 2024 00:19:20 +0000 (20:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 15 May 2024 00:19:20 +0000 (20:19 -0400)
commit8e0e99972ad92cc128c18bc6af41ef0e4d89e7ae
tree95397b7e2df0e5ed477e83e0a87df675fbcefbcd
parentc1664c8eefad0a034d64adde1c2ff70d23be6a2c
Fix handling of polymorphic output arguments for procedures.

Most of the infrastructure for procedure arguments was already
okay with polymorphic output arguments, but it turns out that
CallStmtResultDesc() was a few bricks shy of a load here.  It thought
all it needed to do was call build_function_result_tupdesc_t, but
that function specifically disclaims responsibility for resolving
polymorphic arguments.  Failing to handle that doesn't seem to be
a problem for CALL in plpgsql, but CALL from plain SQL would get
errors like "cannot display a value of type anyelement", or even
crash outright.

In v14 and later we can simply examine the exposed types of the
CallStmt.outargs nodes to get the right type OIDs.  But it's a lot
more complicated to fix in v12/v13, because those versions don't
have CallStmt.outargs, nor do they do expand_function_arguments
until ExecuteCallStmt runs.  We have to duplicatively run
expand_function_arguments, and then re-determine which elements
of the args list are output arguments.

Per bug #18463 from Drew Kimball.  Back-patch to all supported
versions, since it's busted in all of them.

Discussion: https://postgr.es/m/18463-f8cd77e12564d8a2@postgresql.org
src/backend/commands/functioncmds.c
src/pl/plpgsql/src/expected/plpgsql_call.out
src/pl/plpgsql/src/sql/plpgsql_call.sql
src/test/regress/expected/create_procedure.out
src/test/regress/sql/create_procedure.sql