Re: Variadic parameters vs parameter defaults - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: Variadic parameters vs parameter defaults
Date
Msg-id 877i5zoc2a.fsf@oxford.xeocode.com
Whole thread Raw
In response to Variadic parameters vs parameter defaults  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Variadic parameters vs parameter defaults  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> A related point is that, because the current code forbids a default
> for a variadic, you can't do something like
>
> create function foo (f1 int, f2 int default = 42, f3 variadic int[] = array[]::int[])
>
> ie there's no way to have defaults on the preceding parameters either.
> I don't know how useful that is, but maybe it's an argument for adopting
> the second solution where you can explicitly specify a default for a
> variadic.
>
> Comments?

Well if you adopt the implicit empty array argument for missing variadic
parameters then you can just allow defaults for trailing parameters before the
final parameter.

I'm inclined to think an implicit empty array makes the most sense. If a
function-writer wants to enforce a minimum number of arguments they can check
and throw an error.

The question arises though whether it's useful to have any default other than
an empty array. I don't see a compelling reason.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support!


pgsql-hackers by date:

Previous
From: Emmanuel Cecchet
Date:
Subject: [Fwd: Re: Transactions and temp tables]
Next
From: Josh Berkus
Date:
Subject: Re: Variadic parameters vs parameter defaults