| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix assorted confusion about parameter names. |
| Date: | 2026-11-12 19:53:25 |
| Message-ID: | E1xRarN-00000000TKj-1zn2@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Fix assorted confusion about parameter names.
New-style SQL-language functions failed quite badly if named input
parameters were declared after any output parameters, which is unusual
style but perfectly legal. The parser failed to recognize some of the
input parameter names, and could instead accept output parameter names
if there were any, and assigned the wrong parameter numbers in any
case. ruleutils.c was equally confused and would print the wrong
parameter names when deparsing a new-style function.
This mostly comes down to using get_func_arg_info() and failing to
account for the fact that its output covers both input and output
parameters. In some places the right answer is to use
get_func_input_arg_names() instead, although that has an API just
different enough to trip you up. (I added some comments about that.)
Examining other callers of get_func_arg_info() found some related
breakage: PL/Python didn't do quite the right thing with unnamed
input parameters, and plsample.c was completely broken for any
case involving output parameters at all.
A remaining issue, not dealt with here, is that ruleutils' habit
of deparsing Param references using qualified parameter names is
vulnerable to aliasing problems: if the function name matches
some table alias used within the function then we can emit output
that means something different than we intended.
Bug: #19848
Reported-by: Atish Prakash <125atishprak(at)gmail(dot)com>
Diagnosed-by: Atish Prakash <125atishprak(at)gmail(dot)com>
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19848-c4d5bc38ad4ab8b8@postgresql.org
Backpatch-through: 15
Branch
------
REL_15_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/0f351673b5749c782c35d3627a9ae09dcc62bf98
Modified Files
--------------
src/backend/commands/functioncmds.c | 9 +--
src/backend/utils/adt/ruleutils.c | 29 +++++----
src/backend/utils/fmgr/funcapi.c | 6 +-
src/pl/plpython/plpy_procedure.c | 3 +-
src/test/modules/plsample/plsample.c | 20 +++++--
src/test/regress/expected/create_function_sql.out | 73 ++++++++++++++++++++++-
src/test/regress/sql/create_function_sql.sql | 32 ++++++++++
7 files changed, 151 insertions(+), 21 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2026-11-12 20:23:29 | pgsql: Update .abi-compliance-history for a new field in JoinPathExtraD |
| Previous Message | Tom Lane | 2026-11-12 17:18:36 | pgsql: Make float8_regr_combine() handle edge cases like float8_regr_ac |