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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-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 Content-Type Size
variadic_functions.diff.gz application/x-gzip 5.3 KB
json.tgz application/x-gzip 2.4 KB

Browse pgsql-hackers by date

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

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-01-26 19:27:43 Re: sinval contention reduction
Previous Message Simon Riggs 2008-01-26 09:38:48 Re: sinval contention reduction