CREATE AGGREGATE on jsonb concat

Started by Seamus Absherealmost 9 years ago4 messagesgeneral
Jump to latest
#1Seamus Abshere
seamus@abshere.net

hi,

We do this in our database:

CREATE AGGREGATE jsonb_collect(jsonb) (
SFUNC = 'jsonb_concat',
STYPE = jsonb,
INITCOND = '{}'
);

Is there some other built-in aggregate I'm missing that would do the
same thing? It just feels like such an obvious feature.

Thanks for your advice,
Seamus

--
Seamus Abshere, SCEA
https://github.com/seamusabshere
https://linkedin.com/in/seamusabshere
https://www.faraday.io

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Seamus Abshere (#1)
Re: CREATE AGGREGATE on jsonb concat

Seamus Abshere <seamus@abshere.net> writes:

We do this in our database:

CREATE AGGREGATE jsonb_collect(jsonb) (
SFUNC = 'jsonb_concat',
STYPE = jsonb,
INITCOND = '{}'
);

Is there some other built-in aggregate I'm missing that would do the
same thing? It just feels like such an obvious feature.

Doesn't jsonb_agg() do exactly that?

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Seamus Abshere
seamus@abshere.net
In reply to: Tom Lane (#2)
Re: CREATE AGGREGATE on jsonb concat

Seamus Abshere <seamus@abshere.net> writes:

We do this in our database:

CREATE AGGREGATE jsonb_collect(jsonb) (
SFUNC = 'jsonb_concat',
STYPE = jsonb,
INITCOND = '{}'
);

Is there some other built-in aggregate I'm missing that would do the
same thing? It just feels like such an obvious feature.

On Thu, Jul 6, 2017, at 04:53 PM, Tom Lane wrote:
Doesn't jsonb_agg() do exactly that?

hi Tom,

That aggregates into an array. Our `jsonb_collect` aggregates into an
object.

Best,
Seamus

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Seamus Abshere
seamus@abshere.net
In reply to: Seamus Abshere (#3)
Re: CREATE AGGREGATE on jsonb concat

Seamus Abshere <seamus@abshere.net> writes:

That aggregates into an array. Our `jsonb_collect` aggregates into an object.

Postgres 9.6 has (per
https://www.postgresql.org/docs/9.6/static/functions-aggregate.html):

* jsonb_agg(expression)
* jsonb_object_agg(name, value)

In retrospect, I think what I am proposing is:

* jsonb_object_agg(expression)

Is that sane?

Best,
Seamus

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general