From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: json and aggregate |
Date: | 2013-11-04 21:15:34 |
Message-ID: | 1383599734773-5776920.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Diway wrote
> I could use something like this (not tested!)
> --
> select fk_item_header_id as id, json_agg(row(message_id, dt_created,
> lines, size, current_part, status, fk_item_cat_id)) as data from item
> group by fk_item_header_id;
> --
CREATE TYPE
http://www.postgresql.org/docs/9.3/interactive/sql-createtype.html
Since you have a known set of columns you define a custom type that matches
the structure and then:
SELECT fk_item_header_id, json_agg( ( message_id, dt_create, ...
)::custom_type ) FROM ...;
Not tested as I do not have a JSON capable release available at the moment.
But since the type information includes the column names the conversion to
JSON should keep those names intact.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/json-and-aggregate-tp5776903p5776920.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | George Woodring | 2013-11-08 16:51:35 | Query specific table using relative position in search path |
Previous Message | Diway | 2013-11-04 21:05:25 | Re: json and aggregate |