Re: idea: simple variadic functions in SQL and PL/pgSQL - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: idea: simple variadic functions in SQL and PL/pgSQL
Date
Msg-id 162867790802270620w5312d94ev16bc773be41e5dcc@mail.gmail.com
Whole thread Raw
In response to Re: idea: simple variadic functions in SQL and PL/pgSQL  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Hello

On 26/02/2008, Andrew Dunstan <andrew@dunslane.net> wrote:
>
>
>  Pavel Stehule wrote:
>  > Hello,
>  >
>  > I found easy implementation of variadic functions. It's based on
>  > adapation FuncnameGetCandidates. When I found variadic function, then
>  > I should create accurate number of last arguments (diff between
>  > pronargs and nargs). Variadic function can be signed via flag or via
>  > some pseudotype. Flag is better - allows variadic arguments of any
>  > type. In static languages (like SQL or PL/pgSQL) variadic variables
>  > can ba accessed via array (variadic arguments can be only nonarray).
>  > This isn't problem in C language, there are arguments available
>  > directly.
>  >
>
>
> There are a whole slew of questions around this, ISTM.

sure. It's time to thing about it.

>
>  For example: What will be the type inferred for the array of variadic
>  args in plpgsql?

SQL and PL/SQL should be limited.  In my prototype I use fragment:
               /* replace ANYNONARRAYS argument with ARRAY OF some */              argtype = get_array_type(argtype);
          if (!OidIsValid(argtype))                                   ereport(ERROR,
   (errcode(ERRCODE_DATATYPE_MISMATCH),                                         errmsg("could not determine
 
actual array type for variadic argument")));

SPI is unlimited (C language). I can use list of arrays in perl or
python - there I don't see complications too. Domains and arrays can
be problem. Using variadic array variables isn't typical. So I will to
solve only domains. But it's more general problem. Maybe 8.4 can
support array of domains.

>
>  If we are going to do this I think we need some discussion on design
>  before we rush into it.
>

yes, I agree. Variadic functions are simple. And I belive it can
simplify life to some programmers that have to manage functions like:

foo(int),
foo(int, int)
foo(int, int, int)...

regards
Pavel



>  cheers
>
>
>  andrew
>
>
>
>


pgsql-hackers by date:

Previous
From: "Pavel Stehule"
Date:
Subject: proposal: plpgsql return execute ...
Next
From: Magnus Hagander
Date:
Subject: Re: OSSP can be used in the windows environment now!