Re: Variadic parameters vs parameter defaults

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Variadic parameters vs parameter defaults
Date: 2008-12-17 00:55:09
Message-ID: 877i5zoc2a.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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!

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2008-12-17 01:02:47 Re: Variadic parameters vs parameter defaults
Previous Message Emmanuel Cecchet 2008-12-17 00:33:00 [Fwd: Re: Transactions and temp tables]