Re: json support for composites in upcoming 9.2

From: jan zimmek <jan(dot)zimmek(at)web(dot)de>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: json support for composites in upcoming 9.2
Date: 2012-08-13 18:01:23
Message-ID: B7465488-AE89-4DB6-9672-0CDEDB0BF820@web.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

big thanks, this is exactly what i was looking for.

jan

Am 13.08.2012 um 17:58 schrieb Merlin Moncure <mmoncure(at)gmail(dot)com>:

> On Sat, Aug 11, 2012 at 7:05 AM, jan zimmek <jan(dot)zimmek(at)web(dot)de> wrote:
>> hi,
>>
>> i am looking into json support of the upcoming 9.2 release and have a question about the row_to_json function. is there a way to specify the column aliases of a nested composite row without creating a custom type ?
>>
>> here is an example:
>>
>> select
>> row_to_json(t1)
>> from (
>> select
>> 'joe' as username,
>> row(1, 'prj1') project
>> ) t1;
>>
>> the output is:
>>
>> {"username":"joe","project":{"f1":1,"f2":"prj1"}}
>>
>> i want the output to be:
>>
>> {"username":"joe","project":{"project_id":1,"project_name":"prj1"}}
>>
>> i thought of something like this:
>>
>> select
>> row_to_json(t1)
>> from (
>> select
>> 'joe' as username,
>> (select * from (values(1, 'prj1')) as project(project_id, project_name)) as project
>> ) t1;
>>
>> but this fails with "ERROR: subquery must return only one column".
>
> select
> row_to_json(t1)
> from (
> select
> 'joe' as username,
> (select project from (values(1, 'prj1')) as project(project_id,
> project_name)) as project
> ) t1;
>
> merlin
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike Roest 2012-08-13 18:14:37 Automatic checkpoints not running on streaming slave
Previous Message Merlin Moncure 2012-08-13 15:58:33 Re: json support for composites in upcoming 9.2