Re: variadic function support

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: variadic function support
Date: 2008-06-23 16:46:28
Message-ID: 485FD364.5070203@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Pavel Stehule wrote:
> Hello
>
> this patch enhance current syntax of CREATE FUNCTION statement. It
> allows creating functions with variable number of arguments. This
> version is different than last my patches. It doesn't need patching
> PL. Basic idea is transformation of real arguments (related to
> declared variadic argument) to array. All changes are mostly in
> parser.
>
> Demo:
> CREATE FUNCTION public.least(double precision[]) RETURNS double precision AS $$
> SELECT min($1[i])
> FROM generate_subscripts($1,1) g(i)
> $$ LANGUAGE SQL VARIADIC;
>
> SELECT public.least(3,2,1);
> least
> -------
> 1
> (1 row)
>
> SELECT public.least(3,2,1,0,-1);
> least
> -------
> -1
> CREATE FUNCTION concat(varchar, anyarray) RETURNS varchar AS $$
> SELECT array_to_string($2, $1);
> $$ LANGUAGE SQL VARIADIC;
>
> SELECT concat('-',2008,10,12);
> concat
> ------------
> 2008-10-12
> (1 row)
>
>
>
>

And what about a function that takes 2 arrays as arguments?

This proposal strikes me as half-baked. Either we need proper and full
support for variadic functions, or we don't, but I don't think we need
syntactic sugar like the above (or maybe in this case it's really
syntactic saccharine).

cheers

andrew

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-06-23 18:10:24 Re: variadic function support
Previous Message Pavel Stehule 2008-06-23 13:13:22 variadic function support