Re: allow referring to functions without arguments when unique

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: allow referring to functions without arguments when unique
Date: 2017-03-14 07:03:05
Message-ID: CAB7nPqTPemrBc4vuBSrbZ_j1MdGHxa924nmoRt4-6yqs-uOb_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 10, 2017 at 2:03 PM, Peter Eisentraut
<peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:
> On 3/7/17 00:32, Michael Paquier wrote:
>>> @@ -7198,6 +7198,33 @@ function_with_argtypes:
>>> n->objargs = extractArgTypes($2);
>>> $$ = n;
>>> }
>>> This may not have arguments listed, so is function_with_argtypes really adapted?
>
> Well, we could do something like function_with_opt_argtypes?

I don't have a good idea about this name, so let's just keep it as-is...

>>> The comment at the top of LookupFuncName() needs a refresh. The caller
>>> can as well just use a function name without arguments.
>
> Fixed.
>
>> =# set search_path to 'public,popo';
>
> I think you mean
>
> set search_path to public,popo;

Thanks. Right.

>> =# drop function dup2;
>> ERROR: 42883: function dup2() does not exist
>> LOCATION: LookupFuncName, parse_func.c:1944
>> In this case I would have expected an error telling that the name is
>> ambiguous. FuncnameGetCandidates() returns an empty list.
>
> Your example works correctly if you set the schema path correctly.
> However, the error message is misleading with the parentheses. I have
> updated that to create a different error message for this case, and
> added a test case.

+ {
+ if (!noError)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("could not find a function named \"%s\"",
+ NameListToString(funcname))));
+ }

Finally found out what I was looking for in the comments at the top of
FuncnameGetCandidates():
* We search a single namespace if the function name is qualified, else
* all namespaces in the search path. In the multiple-namespace case,
* we arrange for entries in earlier namespaces to mask identical entries in
* later namespaces.
And this correctly matches what your patch is doing, aka only the
first function found is removed and the next ones are discarded.

This looks good to me, so switched as ready for committer.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2017-03-14 07:31:15 Re: background sessions
Previous Message Andres Freund 2017-03-14 06:53:00 Re: WIP: Faster Expression Processing v4