WIP: transformation hook modules and JSON support
От | Pavel Stehule |
---|---|
Тема | WIP: transformation hook modules and JSON support |
Дата | |
Msg-id | 162867790903290341h357c4e8dj8f1c0f0b91271c4d@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: WIP: transformation hook modules and JSON support
|
Список | pgsql-hackers |
Hello I am sending samples of transformation hook modules. One module is JSON support:. >From these modules only JSON support has general usage - so only JSON should be integrated to core. Regards Pavel Stehule === README === JSON generating functions - this module contains functions, that allows simply generation JSON objects. Inspiration of this module was Json library http://www.mysqludf.org/lib_mysqludf_json/index.php . note: an result isn't same as Roland library. Roland more respect javascript rules. This library more respect JSON standard from json.org.. RAW parameters and labeled parameters ----------------------------------- PostgreSQL parser ensure well typed parameters for any functions. Types of parameters. are described in pg_proc record. Exception from this rule are raw parameters (of "any" type). Raw parameters are passed without any conversion.. Sample of function with raw parameters is function json_array: postgres=# select json.json_array(10,20,30,'Pavel',current_date); json_array............ --------------------------------- [10,20,30,"Pavel","2009-03-28"] (1 row) postgres=# select json.json_array(10,20,30,'Pavel',json.json_array(20,30), true, false); json_array............... --------------------------------------- [10,20,30,"Pavel",[20,30],true,false] (1 row) Smart parameter take some addition info from calling environment. One sample of smart parameter's function is SQL/XML function xmforest.. Json library use raw parameters for automatical double quotes wrapping of string values. json_object functions use labeled parameters. Aditional info use as property name.. postgres=# select json_object(10,'akaka',29); ERROR: invalid input syntax for integer: "akaka" LINE 1: select json_object(10,'akaka',29); ^ postgres=# load 'json'; LOAD Time: 1,677 ms postgres=# select json_object(10,'akaka',29); ERROR: unnamed JSON attribute must be a column reference LINE 1: select json_object(10,'akaka',29); ^ postgres=# select json_object(10 as b,'akaka' as c,29 as x); json_object...... ----------------------- {b:10,c:"akaka",x:29} 1 row) Function json_members is very specific. PostgreSQL definition should be like json_members(text, "any", text, "any", text, "any", ...). Parameters are pairs of property name and json value. First in pair should be text or any type with implicit cast to text. postgres=# select json.json_members('a',2,'b',current_date); json_members...... ------------------------ "a":2,"b":"2009-03-29" (1 row) postgres=# select json.json_object(json.json_members('a',2,'b',current_date)); json_object........ -------------------------- {"a":2,"b":"2009-03-29"} (1 row)
Вложения
В списке pgsql-hackers по дате отправления: