From: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
---|---|
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 22:31:47 |
Message-ID: | 87lg46tzr3.fsf@news-spur.riddles.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>>>>> "Andrew" == Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
>>>>> "Rory" == Rory Campbell-Lange <rory(at)campbell-lange(dot)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.
Andrew> where j @> '{"people":[{"id":2003}]}'
Andrew> (meaning: j contains a key "people" whose value is an array
Andrew> containing an element {"id":2003})
or to be more precise: j is an object containing a key "people" whose
value is an array containing an element which is an object containing a
key "id" with value 2003
i.e. {"a":3, "people": [{"id":2003,"blah":123},{"id":2004}]} would
match the condition too.
--
Andrew (irc:RhodiumToad)
From | Date | Subject | |
---|---|---|---|
Next Message | Chuck Martin | 2018-12-30 23:17:08 | Re: getting pg_basebackup to use remote destination |
Previous Message | Andrew Gierth | 2018-12-30 22:14:19 | Re: jsonb : find row by array object attribute |