Re: JSON for PG 9.2

Andrew Dunstan <andrew@dunslane.net>

From: Andrew Dunstan <andrew@dunslane.net>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>, Joey Adams <joeyadams3.14159@gmail.com>, Robert Haas <robertmhaas@gmail.com>, "David E. Wheeler" <david@kineticode.com>, Claes Jakobsson <claes@surfar.nu>, Dimitri Fontaine <dimitri@2ndquadrant.fr>, Magnus Hagander <magnus@hagander.net>, Jan Urbański <wulczer@wulczer.org>, Simon Riggs <simon@2ndquadrant.com>, Bruce Momjian <bruce@momjian.us>, PostgreSQL-development Hackers <pgsql-hackers@postgresql.org>, Jan Wieck <janwieck@yahoo.com>
Date: 2012-01-12T16:28:10Z
Lists: pgsql-hackers

On 01/12/2012 11:21 AM, Merlin Moncure wrote:
> On Thu, Jan 12, 2012 at 9:51 AM, Andrew Dunstan<andrew@dunslane.net>  wrote:
>> On 01/12/2012 10:44 AM, Pavel Stehule wrote:
>>> this should be little bit more enhanced to support a row arrays - it
>>> can be merged with some routines from pst tool
>>> http://okbob.blogspot.com/2010/11/new-version-of-pst-collection-is.html
>> I will be covering composites.
> curious, will your function work on unregistered composites?  What
> would this do?
>
> select array_to_json(array[row('a', 1), row('b', 2)]);
>


Expected behaviour is something like this:

    andrew=# select q2json('
       select $$a$$ || x as b,
              y as c,
              array[row(x.*,array[1,2,3]),
                    row(y.*,array[4,5,6])] as z
       from generate_series(1,2) x,
            generate_series(4,5) y');

      [{"b":"a1","c":4,"z":[{"f1":1,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]},
       {"b":"a1","c":5,"z":[{"f1":1,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]},
       {"b":"a2","c":4,"z":[{"f1":2,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]},
       {"b":"a2","c":5,"z":[{"f1":2,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}]

cheers

andrew