pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix assorted confusion about parameter names.
Date: Thu, 12 Nov 2026 19:53:25 +0000
Message-ID: <E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org> (raw)

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@gmail.com>
Diagnosed-by: Atish Prakash <125atishprak@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19848-c4d5bc38ad4ab8b8@postgresql.org
Backpatch-through: 15

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8e27c9261c9dd6127e16ced998d37ed7a8cb2b7d

Modified Files
--------------
src/backend/commands/functioncmds.c               |  9 +--
src/backend/utils/adt/ruleutils.c                 | 30 ++++++----
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, 152 insertions(+), 21 deletions(-)



view thread (6+ messages)

Message-ID: <E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org>
Permalink:  ../E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix assorted confusion about parameter names.
  In-Reply-To: <E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org>
  References: <E1xRarN-00000000TKZ-1Zlx@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox