Tighten enforcement of variable CONSTANT markings in plpgsql.
I noticed that plpgsql would allow assignment of a new value to a
variable even when that variable is marked CONSTANT, if the variable
is used as an output parameter in CALL or is a refcursor variable
that OPEN assigns a new value to. Fix these oversights.
In the CALL case, the check has to be done at runtime because we
cannot know at parse time which parameters are OUT parameters.
For OPEN, it seems best to likewise enforce at runtime because
then we needn't throw error if the variable has a nonnull value
(since OPEN will only try to overwrite a null value).
Although this is surely a bug fix, no back-patch: it seems unlikely
that anyone would thank us for breaking formerly-working code in
minor releases.
Discussion: https://postgr.es/m/214453.1651182729@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ccd10a9bfa54c1aad3561232bf24222f1b455e1c
Modified Files
--------------
src/pl/plpgsql/src/expected/plpgsql_call.out | 12 ++++++
src/pl/plpgsql/src/pl_exec.c | 63 ++++++++++++++++++++++++++--
src/pl/plpgsql/src/sql/plpgsql_call.sql | 12 ++++++
src/test/regress/expected/plpgsql.out | 27 ++++++++++++
src/test/regress/sql/plpgsql.sql | 24 +++++++++++
5 files changed, 134 insertions(+), 4 deletions(-)