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