pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
3+ messages / 2 participants
[nested] [flat]

* Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
@ 2022-05-03 22:03 Bryn Llewellyn <bryn@yugabyte.com>
  2022-05-03 22:22 ` Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Bryn Llewellyn @ 2022-05-03 22:03 UTC (permalink / raw)
  To: pgsql-general list <pgsql-general@lists.postgresql.org>

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.

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

* Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
  2022-05-03 22:03 Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Bryn Llewellyn <bryn@yugabyte.com>
@ 2022-05-03 22:22 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-05-03 22:48   ` Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Bryn Llewellyn <bryn@yugabyte.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2022-05-03 22:22 UTC (permalink / raw)
  To: Bryn Llewellyn <bryn@yugabyte.com>; +Cc: pgsql-general list <pgsql-general@lists.postgresql.org>

Bryn Llewellyn <bryn@yugabyte.com> writes:
> 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?

It is, see

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=ccd10a9bf

			regards, tom lane





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

* Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter
  2022-05-03 22:03 Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Bryn Llewellyn <bryn@yugabyte.com>
  2022-05-03 22:22 ` Re: Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-05-03 22:48   ` Bryn Llewellyn <bryn@yugabyte.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Bryn Llewellyn @ 2022-05-03 22:48 UTC (permalink / raw)
  To: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>; +Cc: pgsql-general list <pgsql-general@lists.postgresql.org>

> tgl@sss.pgh.pa.us wrote:
> 
>> bryn@yugabyte.com wrote:
>> 
>> 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?
> 
> It is, see https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=ccd10a9bf

Thanks for the instant response, Tom. It's uncanny that you spotted this on Saturday 30-Apr and I spotted it just three days later on Tuesday 3-May. One of us must be psychic.=

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


end of thread, other threads:[~2022-05-03 22:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03 22:03 Meaning of "constant" not honored when the variable is used as the actual for a proc's OUT formal paameter Bryn Llewellyn <bryn@yugabyte.com>
2022-05-03 22:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-05-03 22:48   ` Bryn Llewellyn <bryn@yugabyte.com>

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