Skip site navigation (1) Skip section navigation (2)

variadic function support

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: variadic function support
Date: 2008-06-23 13:13:22
Message-ID: 162867790806230613w5719d25ejd2a03fac84792d18@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-patches
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)


Regards
Pavel Stehule

Attachment: variadic.1.0.0.diff.gz
Description: application/x-gzip (88.5 KB)

Responses

pgsql-patches by date

Next:From: Andrew DunstanDate: 2008-06-23 16:46:28
Subject: Re: variadic function support
Previous:From: ITAGAKI TakahiroDate: 2008-06-23 06:22:57
Subject: WIP: executor_hook for pg_stat_statements

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group