pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
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 22:14:19 +0000
Message-ID: <87pntiu0n9.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net>
References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net>

>>>>> "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)




view thread (4+ messages)  latest in thread

Message-ID: <87pntiu0n9.fsf@news-spur.riddles.org.uk>
Permalink:  ../87pntiu0n9.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87pntiu0n9.fsf@news-spur.riddles.org.uk

 · 

reply

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: andrew@tao11.riddles.org.uk, rory@campbell-lange.net
  Subject: Re: jsonb : find row by array object attribute
  In-Reply-To: <87pntiu0n9.fsf@news-spur.riddles.org.uk>
  References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> <87pntiu0n9.fsf@news-spur.riddles.org.uk>

* 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