Re: Extracting data from jsonb array? - Mailing list pgsql-general

From Tom Lane
Subject Re: Extracting data from jsonb array?
Date
Msg-id 3210187.1607400978@sss.pgh.pa.us
Whole thread Raw
In response to Re: Extracting data from jsonb array?  (Ken Tanzer <ken.tanzer@gmail.com>)
Responses Re: Extracting data from jsonb array?
List pgsql-general
Ken Tanzer <ken.tanzer@gmail.com> writes:
>> => select f.id, f.f1,f.f2,array_agg(t.key2) from foo as f,
>> jsonb_to_recordset(js) as t(key2 text) group by f.id;

> After a little more thought and experimenting, I'm not so sure about this
> part.  In particular, I'm not clear why Postgres isn't complaining about
> the f1 and f2 fields.  (It's not giving the "must appear in the GROUP BY
> clause or be used in an aggregate function" error that I would expect, and
> that I am getting when I try to apply this to my real query.)

> Can anyone explain to me why those fields don't need to be grouped?  Thanks.

If foo.id is a primary key, it knows that the "group by" doesn't really
merge any rows of foo, so it lets you get away with that.  I think this
is actually required by spec, but am too lazy to go check right now.

If foo.id isn't a primary key, then I'm confused too.  Can we see the
full declaration of the table?

            regards, tom lane



pgsql-general by date:

Previous
From: Steve Baldwin
Date:
Subject: Re: Extracting data from jsonb array?
Next
From: Steve Baldwin
Date:
Subject: Re: Extracting data from jsonb array?