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

From Andrew Gierth
Subject Re: jsonb : find row by array object attribute
Date
Msg-id 87pntiu0n9.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to jsonb : find row by array object attribute  (Rory Campbell-Lange <rory@campbell-lange.net>)
Responses Re: jsonb : find row by array object attribute  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
List pgsql-general
>>>>> "Rory" == Rory Campbell-Lange <rory@campbell-lange.net> writes:

 Rory> and data like this:
 Rory>                             j                         
 Rory>     --------------------------------------------------
 Rory>      {"a": 1, "people": [{"id": 2002}, {"id": 2004}]}
 Rory>      {"a": 3, "people": [{"id": 2003}, {"id": 2005}]}
 Rory>     (2 rows)

 Rory> I'd like to be able to find any row with a particular people id
 Rory> attribute.

where j @> '{"people":[{"id":2003}]}'

(meaning: j contains a key "people" whose value is an array containing
an element {"id":2003})

Since @> can use GIN indexes, you should usually try and find a search
condition using it before resorting to playing with -> or expanding out
array values.

-- 
Andrew (irc:RhodiumToad)


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: jsonb : find row by array object attribute
Next
From: Andrew Gierth
Date:
Subject: Re: jsonb : find row by array object attribute