WIP: variadic function, named params - Mailing list pgsql-hackers

From Pavel Stehule
Subject WIP: variadic function, named params
Date
Msg-id 162867790801260650t32ab221t5d6aac36643bac50@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hello,

there is one implementation of variadic functions. The base premis is
transformation type:

anyparams -> n x any
anyelements -> n x anyelement

Currently variadic functions can be only in C language. PL/pgSQL
cannot access to array of params. I implented some JSON functions
(based on Bauman's libraries for MySQL). With this extension we are
able to write some sophistic libraries.

What do you thing about this concept? Has any sense continue in this project?

Regards
Pavel Stehule



postgres=# select json_members('aaa',1,'cccc',20);
   json_members
-------------------
 "aaa":1,"cccc":20
(1 row)

postgres=# select json_members('aaa',1);
 json_members
--------------
 "aaa":1
(1 row)

postgres=# select * from fog;
 a |  b   |     c
---+------+------------
   | ahoj |
   | ahoj | 2008-01-26
 1 |      | 2008-01-26
(3 rows)


postgres=# select json_object(a,b,c as cc) from fog;
           json_object
----------------------------------
 {a:NaN,b:"ahoj",cc:null}
 {a:NaN,b:"ahoj",cc:"2008-01-26"}
 {a:1,b:null,cc:"2008-01-26"}
(3 rows)

postgres=# select json_object('Pavel' as name, 'Stehule' as surname);
           json_object
----------------------------------
 {name:"Pavel",surname:"Stehule"}
(1 row)

postgres=# select json_array(a,b,c) from fog;
        json_array
---------------------------
 [NaN,"ahoj",null]
 [NaN,"ahoj","2008-01-26"]
 [1,null,"2008-01-26"]
(3 rows)

CREATE OR REPLACE FUNCTION json_array(anyparams) RETURNS json
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;

CREATE OR REPLACE FUNCTION json_object(anyparams) RETURNS json
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;

CREATE OR REPLACE FUNCTION json_members(anyparams) RETURNS json
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;

Attachment

pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Truncate Triggers
Next
From: Robert Treat
Date:
Subject: Re: PostgreSQL Programmer's Guide Books