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

WIP: variadic function, named params

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: Patches <pgsql-patches(at)postgresql(dot)org>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: WIP: variadic function, named params
Date: 2008-01-26 14:50:52
Message-ID: 162867790801260650t32ab221t5d6aac36643bac50@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
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: json.tgz
Description: application/x-gzip (2.4 KB)
Attachment: variadic_functions.diff.gz
Description: application/x-gzip (5.3 KB)

pgsql-hackers by date

Next:From: Robert TreatDate: 2008-01-26 15:28:49
Subject: Re: PostgreSQL Programmer's Guide Books
Previous:From: Stephen FrostDate: 2008-01-26 01:23:22
Subject: Re: Truncate Triggers

pgsql-patches by date

Next:From: Tom LaneDate: 2008-01-26 19:27:43
Subject: Re: sinval contention reduction
Previous:From: Simon RiggsDate: 2008-01-26 09:38:48
Subject: Re: sinval contention reduction

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