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

From Brendan Jurd
Subject Re: Variadic parameters vs parameter defaults
Date
Msg-id 37ed240d0812161943k77a2130cna3688f8bb7ff133b@mail.gmail.com
Whole thread Raw
In response to Re: Variadic parameters vs parameter defaults  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Variadic parameters vs parameter defaults
List pgsql-hackers
On Wed, Dec 17, 2008 at 12:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Actually, I just realized that there's another fly in the ointment:
> the current variadic code allows "variadic anyarray", which is
> equivalent to an appropriate number of anyelement arguments.  If we
> allow defaulting then there's a big problem: no principled way to
> decide what type the empty array is.

I see your point.  Polymorphic + variadic is tricky.

Because Postgres cannot determine the "default" type for the empty
variadic anyarray argument, I think it makes sense to throw an error
in this case.

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".

NB I have no idea whether such an approach would be practical to
implement, but I think it's the least astonishing set of behaviours.

Cheers,
BJ


pgsql-hackers by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Looking for someone with MinGW
Next
From: "Robert Haas"
Date:
Subject: Re: Another issue in default-values patch: defaults expanded too soon