Re: jsonb : find row by array object attribute

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: jsonb : find row by array object attribute
Date: 2018-12-30 21:47:10
Message-ID: 15217.1546206430@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rory Campbell-Lange <rory(at)campbell-lange(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gierth 2018-12-30 22:14:19 Re: jsonb : find row by array object attribute
Previous Message Rory Campbell-Lange 2018-12-30 21:31:12 jsonb : find row by array object attribute