pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix assorted confusion about parameter names.
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c6e70d5d37557a22fd41fbd6dae9d71ac4545129

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/64e8d6f8945a6dbc39250431899ae7b98ccbdf64

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c87192d13dcd933256b1a2858bc4ddf2c1eb56d7

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4343c135e794a47465e6732c8c1975a6fe92a74f

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix assorted confusion about parameter names.
@ 2026-11-12 19:53 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2026-11-12 19:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-12 19:53 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>
2026-11-12 19:53 pgsql: Fix assorted confusion about parameter names. Tom Lane <tgl@sss.pgh.pa.us>

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