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

From Bryn Llewellyn
Subject Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
Date
Msg-id AD24E528-98A5-4961-A72F-0F9D402E42A4@yugabyte.com
Whole thread Raw
Responses Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
List 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.

pgsql-general by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Re: Backing up a DB excluding certain tables
Next
From: Tom Lane
Date:
Subject: Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter