Re: pl/pgsql feature request: shorthand for argument and local variable references - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: pl/pgsql feature request: shorthand for argument and local variable references
Date
Msg-id CAMT0RQTLUQwvXJ64dNMNPkXiOXtwY6g=EzUCAmAv0Or1zcyUig@mail.gmail.com
Whole thread Raw
In response to Re: pl/pgsql feature request: shorthand for argument and local variable references  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: pl/pgsql feature request: shorthand for argument and local variable references  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
On Thu, Mar 18, 2021 at 4:23 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:

> But we don't support this feature. We are changing just a top scope's label. So syntax "ALIAS FOR FUNCTION is not
good.The user can have false hopes
 

In this case it looks like it should go together with other labels and
have << label_here >> syntax ?

And we are back to the question of where to put this top scope label :)

Maybe we cloud still pull in the function arguments into the outermost
blocks scope, and advise users to have an extra block if they want to
have same names in both ?


CREATE OR REPLACE FUNCTION fx(a int, b int)
RETURNS ... AS $$
<< fnargs >>
BEGIN
  << topblock >>
  DECLARE
    a int := fnargs.a * 2;
    b int := topblock.a + 2;
  BEGIN
    ....
  END;
END;
$$;

and we could make the empty outer block optional and treat two
consecutive labels as top scope label and outermost block label

CREATE OR REPLACE FUNCTION fx(a int, b int)
RETURNS ... AS $$
<< fnargs >>
<< topblock >>
  DECLARE
    a int := fnargs.a * 2;
    b int := topblock.a + 2;
  BEGIN
    ....
END;
$$;

But I agree that this is also not ideal.


And

CREATE OR REPLACE FUNCTION fx(a int, b int)
WITH (TOPSCOPE_LABEL fnargs)
RETURNS ... AS $$
<< topblock >>
  DECLARE
    a int := fnargs.a * 2;
    b int := topblock.a + 2;
  BEGIN
    ....
END;
$$;

Is even more inconsistent than #option syntax


Cheers
Hannu

PS:

>
> For cleanness/orthogonality I would also prefer the blocklables to be in DECLARE
> for each block, but this train has already left :)
> Though we probably could add alternative syntax ALIAS FOR BLOCK ?

>
> why? Is it a joke?
>
> you are defining a block label, and you want to in the same block redefine some outer label? I don't think it is a
goodidea.
 



pgsql-hackers by date:

Previous
From: David Steele
Date:
Subject: Re: invalid data in file backup_label problem on windows
Next
From: Bruce Momjian
Date:
Subject: Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?