Re: jsonb : find row by array object attribute - Mailing list pgsql-general

From Tom Lane
Subject Re: jsonb : find row by array object attribute
Date
Msg-id 15217.1546206430@sss.pgh.pa.us
Whole thread Raw
In response to jsonb : find row by array object attribute  (Rory Campbell-Lange <rory@campbell-lange.net>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Rory Campbell-Lange
Date:
Subject: jsonb : find row by array object attribute
Next
From: Andrew Gierth
Date:
Subject: Re: jsonb : find row by array object attribute