Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
Date: 2022-05-03 22:03:32
Message-ID: AD24E528-98A5-4961-A72F-0F9D402E42A4@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I just did this using PG 14.2:

create procedure p(a out int)
language plpgsql
as $body$
begin
a := 42;
end;
$body$;

do $body$
declare
a constant int := 0;
begin
call p(a);
raise info '%', a::text;
end;
$body$;

The DO block runs without error and reports "INFO: 42". This is an unambiguous semantic error because "a" is declared "constant".

Is this a known issue?

Replace "a" with the literal "37" in this test:

do $body$
begin
call p(37);
raise info '%', a::text;
end;
$body$;

This causes the expected runtime error 42601:

procedure parameter "a" is an output parameter but corresponding argument is not writable.

Bt.w., error 42601 is mapped to the name "syntax_error" in PL/pgSQL. I'd say that this is its own distinct bug. The syntax is fine. It's a semantic error.

Notice that the test can be trivially transcribed to Oracle Database's PL/SQL as this SQL*Plus script:

create procedure p(a out integer)
authid definer
as
begin
a := 42;
end;
/
declare
a /*constant*/ int := 0;
begin
p(a);
DBMS_Output.put_line('a: '||to_char(a));
end;
/

When "constant" is commented out (as presented), the anonymous block runs without error and outputs "a: 42". But when "constant" is uncommented, the attempt causes this error:

PLS-00363: expression 'A' cannot be used as an assignment target

This is the proper report of what clearly is a semantic error. PG should do the same.

B.t.w., this happens to be a compilation error in ORCL and not a run-time error. But that's an entirely different story and reflects the fundamentally different compilation and execution models for anonymous blocks, user-defined functions, and user-defined procedures between ORCL and PG.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-05-03 22:22:06 Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
Previous Message Zheng Li 2022-05-03 21:30:20 Re: Support logical replication of DDLs