From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Re: proposal - using names as primary names of plpgsql function parameters instead $ based names |
Date: | 2017-05-20 06:25:32 |
Message-ID: | CAFj8pRDv83X2bW4W73wZUBOts+v0ODwgePOfJfxstxF_bFi=dA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
2017-05-19 5:48 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>
> 2017-05-19 3:14 GMT+02:00 Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)
> com>:
>
>> On 5/15/17 14:34, Pavel Stehule wrote:
>> > Now, I when I working on plpgsql_check, I have to check function
>> > parameters. I can use fn_vargargnos and out_param_varno for list of
>> > arguments and related varno(s). when I detect some issue, I am using
>> > refname. It is not too nice now, because these refnames are $ based.
>> > Long names are alias only. There are not a possibility to find
>> > related alias.
>> >
>> > So, my proposal. Now, we can use names as refname of parameter
>> > variable. $ based name can be used as alias. From user perspective
>> > there are not any change.
>> >
>> > Comments, notes?
>> >
>> > here is a patch
>>
>> I don't understand what this is changing. There are not documentation
>> or test changes.
>>
>
> This change is visible only for tools like plpgsql_check probably and
> similar tools. Now, this info is not available from user space (maybe only
> from some error message, I have to recheck it)
>
> What is changed.
>
> PLpgSQL variables has field refname - it can be used if you iterate over
> variables or it is used for some error messages. When some variables is
> searching, then namespace aliases are used. Now for any function argument
> is created variable with refname "$x" and namespace aliases "$x" and "name"
> if name exists. There are not any way, how to get a aliases related to
> variable. When I raise a warning in plpgsql about function arguments I have
> to print $x based messages, what is not too readable if function has lot of
> parameters.
>
> The proposal is the change of refname "$x" to "name" for all variables
> created for function arguments.
>
> There are another possibilities - maintain list of all aliases for
> variables or dynamically search all related aliases in namespace tree. Both
> little bit more code.
>
I wrote small regression test, where expected behave is visible
master:
postgres=# create or replace function fx(x ct)
returns void as $$
begin
perform 1;
get diagnostics x = row_count;
end;
$$ language plpgsql;
ERROR: "$1" is not a scalar variable
LINE 5: get diagnostics x = row_count;
patched:
postgres=# create or replace function fx(x ct)
returns void as $$
begin
perform 1;
get diagnostics x = row_count;
end;
$$ language plpgsql;
ERROR: "x" is not a scalar variable
LINE 5: get diagnostics x = row_count;
> Regards
>
> Pavel
>
>
>>
>> --
>> Peter Eisentraut http://www.2ndQuadrant.com/
>> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>>
>
>
Attachment | Content-Type | Size |
---|---|---|
psql-named-arguments-02.patch | text/x-patch | 2.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Fabien COELHO | 2017-05-20 07:15:39 | Re: proposal psql \gdesc |
Previous Message | Alvaro Herrera | 2017-05-20 04:58:04 | Re: Improvement in log message of logical replication worker |