From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rory Campbell-Lange <rory@campbell-lange.net>
Cc: pgsql-general@postgresql.org
Subject: Re: jsonb : find row by array object attribute
Date: Sun, 30 Dec 2018 16:47:10 -0500
Message-ID: <15217.1546206430@sss.pgh.pa.us> (raw)
In-Reply-To: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net>
References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net>
Rory Campbell-Lange <rory@campbell-lange.net> writes:
> ... I can't work out how to return the whole row containing a desired
> people id value.
Something like this, maybe?
=# select * from x where
'2003'::jsonb in (select jsonb_array_elements(j #>'{people}')->'id');
j
--------------------------------------------------
{"a": 3, "people": [{"id": 2003}, {"id": 2005}]}
(1 row)
It's not too efficient though :-(
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, rory@campbell-lange.net
Subject: Re: jsonb : find row by array object attribute
In-Reply-To: <15217.1546206430@sss.pgh.pa.us>
References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> <15217.1546206430@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox