Re: [HACKERS] Re: proposal - using names as primary names of plpgsqlfunction parameters instead $ based names - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: [HACKERS] Re: proposal - using names as primary names of plpgsqlfunction parameters instead $ based names
Date
Msg-id CAFj8pRDv83X2bW4W73wZUBOts+v0ODwgePOfJfxstxF_bFi=dA@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] Re: proposal - using names as primary names of plpgsqlfunction parameters instead $ based names  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: [HACKERS] Re: proposal - using names as primary names of plpgsqlfunction parameters instead $ based names  (Jeevan Chalke <jeevan.chalke@enterprisedb.com>)
List pgsql-hackers


2017-05-19 5:48 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:


2017-05-19 3:14 GMT+02:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.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

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Improvement in log message of logical replicationworker
Next
From: Fabien COELHO
Date:
Subject: Re: [HACKERS] proposal psql \gdesc