From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wolfgang Walther <walther@technowledgy.de>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Calling variadic function with default value in named notation
Date: Thu, 29 Oct 2020 11:44:33 -0400
Message-ID: <1549290.1603986273@sss.pgh.pa.us> (raw)
In-Reply-To: <d6a7d0ac-3052-d8ac-f700-7e4decfd4f09@technowledgy.de>
References: <5a80bcdb-e92a-5c21-d923-f3813543771b@technowledgy.de>
<1449498.1603919899@sss.pgh.pa.us>
<d6a7d0ac-3052-d8ac-f700-7e4decfd4f09@technowledgy.de>
Wolfgang Walther <walther@technowledgy.de> writes:
> Tom Lane:
>> You can't write positional arguments after named arguments, so the
>> failure to match isn't all that surprising; that is, to accept this
>> call we'd have to interpret it as a named argument and then an empty
>> list of things to match positionally to the variadic parameter.
> It's not possible to have positional after named arguments and variadic
> arguments always come last. Therefore, once any other argument is named
> (so the call is made with either named or mixed notation) any variadic
> argument will always have to be named. In this case it could be
> interpreted as a named argument, even if absent, so the default value
> should be given.
> The information about the call being in named or mixed notation should
> be available well in advance, when the statement is parsed. Do you think
> it would be possible to "expect a named variadic argument" and then
> fallback to the default in this case?
Looking back at the original discussion about named arguments,
https://www.postgresql.org/message-id/flat/15635.1249842629%40sss.pgh.pa.us
there was quite extensive discussion about how they should interact
with VARIADIC, and we ended up settling on the current behavior,
which is that you must explicitly say VARIADIC if you want a
named-arguments call to match a variadic function. The argument
for requiring that was basically to avoid confusion, which I think
is reasonable.
Now what I don't see in that thread is any mention of the possibility of
allowing the variadic parameter to be defaulted --- which is problematic
with this rule mostly because then there's noplace to write VARIADIC.
Still, the fact that this hasn't come up in ten-plus years says
that it's a pretty niche use case. I'm not sure that it's worth
doing anything about.
I did poke at the code a little bit, and the fact that the function isn't
matched just comes down to these two lines in FuncnameGetCandidates:
if (OidIsValid(procform->provariadic) && expand_variadic)
continue;
If you delete them then all these cases work, but so would some other
ones that I doubt we should allow. I'd be inclined to insist that
the only two cases we should allow are (1) the variadic parameter
isn't listed in the call (so it's defaulted), or (2) it is listed
with an explicit VARIADIC marker (which is the case we allow now).
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, walther@technowledgy.de, david.g.johnston@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Calling variadic function with default value in named notation
In-Reply-To: <1549290.1603986273@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox