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

Re: JSON for PG 9.2

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Hannu Krosing <hannu(at)krosing(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: JSON for PG 9.2
Date: 2012-04-16 14:10:33
Message-ID: 4F8C2859.6050203@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-hackers

On 04/16/2012 09:34 AM, Hannu Krosing wrote:
>> based on Abhijit's feeling and some discussion offline, the consensus
>> seems to be to remove query_to_json.
> The only comment I have here is that query_to_json could have been
> replaced with json_agg, so thet you don't need to do double-buffering
> for the results of array(<yourquery>) call in
>
> SELECT array_to_json(array(<yourquery>));
>
> Or is there some other way to avoid it except to wrap row_to_json()
> calls in own aggregate function which adds enclosing brackets and comma
> separator ( like this : '['<row1>[,<rowN>]']' ?
>
>

The way I usually write this is:

     select array_to_json(array_agg(q))
     from (<yourquery>) q;

It's a pity you didn't make this comment back in January when we were 
talking about this. I think it's too late now in this release cycle to 
be talking about adding the aggregate function.

cheers

andrew

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2012-04-16 14:19:36
Subject: Re: index-only scans vs. Hot Standby, round two
Previous:From: Hannu KrosingDate: 2012-04-16 13:34:12
Subject: Re: JSON for PG 9.2

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