Re: Variadic parameters vs parameter defaults

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Variadic parameters vs parameter defaults
Дата
Msg-id 20958.1229486586@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Variadic parameters vs parameter defaults  ("Brendan Jurd" <direvus@gmail.com>)
Ответы Re: Variadic parameters vs parameter defaults  (Peter Eisentraut <peter_e@gmx.net>)
Re: Variadic parameters vs parameter defaults  (Peter Eisentraut <peter_e@gmx.net>)
Re: Variadic parameters vs parameter defaults  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-hackers
"Brendan Jurd" <direvus@gmail.com> writes:
> So if I had these two functions ...

> var1(a int, b variadic int[])
> var2(a int, b variadic anyarray)

> ... it would be okay to write var1(8), which resolves as var1(8,
> array[]::int[]).  But if I tried to write var2(8) I'd get an error.
> Maybe something like "cannot determine type of missing variadic
> arguments".

Well, we could unify these behaviors if we insisted on an explicit
default to omit the argument in both cases.
var1(a int, b variadic int[] default '{}'::int[])var2(a int, b variadic anyarray default '{}'::text[]) -- perhaps

In both cases, supplying a single argument would be legal if and only
if you provided a default for the variadic parameter.  As soon as you
give two arguments, the default isn't relevant anymore.  This method
eliminates the discrepancy between anyarray and other types of variadic
parameters, and it leaves the door open for someone to use something
besides an empty array as the default.  (Who are we to say that such a
thing is never useful?  NULL seems like a possibly useful default for
instance.)  I think it also makes the variadic and default features
a bit more orthogonal.

This still leaves us with the annoyance of having to prevent changes in
the actual datatype of a default associated with a polymorphic parameter;
but that's just some implementation tedium, and I'm beginning to find
it more attractive than the alternatives.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Robert Haas"
Дата:
Сообщение: Re: Another issue in default-values patch: defaults expanded too soon
Следующее
От: "Pavel Stehule"
Дата:
Сообщение: Re: Another issue in default-values patch: defaults expanded too soon