Re: pl/pgsql feature request: shorthand for argument and local variable references

From: Hannu Krosing <hannuk(at)google(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Julien Rouhaud <rjuju123(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Chapman Flack <chap(at)anastigmatix(dot)net>, Jack Christensen <jack(at)jncsoftware(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pl/pgsql feature request: shorthand for argument and local variable references
Date: 2021-03-19 13:14:24
Message-ID: CAMT0RQTLUQwvXJ64dNMNPkXiOXtwY6g=EzUCAmAv0Or1zcyUig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Mar 18, 2021 at 4:23 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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 good idea.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2021-03-19 13:29:06 Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?
Previous Message David Steele 2021-03-19 13:05:56 Re: invalid data in file backup_label problem on windows