agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: David Johnston <polobo@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: json and aggregate
Date: Mon, 4 Nov 2013 13:15:34 -0800 (PST)
Message-ID: <1383599734773-5776920.post@n5.nabble.com> (raw)
In-Reply-To: <1383599125836-5776914.post@n5.nabble.com>
References: <1383596556949-5776903.post@n5.nabble.com>
<1383597496358-5776905.post@n5.nabble.com>
<1383599125836-5776914.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (4+ messages)
Message-ID: <1383599734773-5776920.post@n5.nabble.com>
Permalink: ../1383599734773-5776920.post@n5.nabble.com/
Also on: postgresql.org/message-id/1383599734773-5776920.post@n5.nabble.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: polobo@yahoo.com
Subject: Re: json and aggregate
In-Reply-To: <1383599734773-5776920.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox