From: | Hannu Krosing <hannu(at)krosing(dot)net> |
---|---|
To: | Andrew Dunstan <andrew(at)dunslane(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 13:34:12 |
Message-ID: | 1334583252.31618.2626.camel@hvost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, 2012-01-31 at 12:58 -0500, Andrew Dunstan wrote:
>
> On 01/30/2012 10:37 AM, Andrew Dunstan wrote:
> >
> >
> >> Aside: is query_to_json really necessary? It seems rather ugly and
> >> easily avoidable using row_to_json.
> >>
> >
> > I started with this, again by analogy with query_to_xml(). But I agree
> > it's a bit ugly. If we're not going to do it, then we definitely need
> > to look at caching the output funcs in the function info. A closer
> > approximation is actually:
> >
> > SELECT array_to_json(array_agg(q))
> > FROM ( your query here ) q;
> >
> >
> > But then I'd want the ability to break that up a bit with line feeds,
> > so we'd need to adjust the interface slightly. (Hint: don't try the
> > above with "select * from pg_class".)
> >
> >
> > I'll wait on further comments, but I can probably turn these changes
> > around very quickly once we're agreed.
> >
> >
> >
>
> 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>]']' ?
> cheers
>
> andrew
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2012-04-16 14:10:33 | Re: JSON for PG 9.2 |
Previous Message | Peter Eisentraut | 2012-04-16 12:39:16 | Re: A typo fix in a comment in xlog.c |