Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdjLv-0005cJ-5z for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 22:14:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdjLt-0006NT-45 for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 22:14:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdjLs-0006NL-Go for pgsql-general@lists.postgresql.org; Sun, 30 Dec 2018 22:14:32 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdjLl-0001gB-2w for pgsql-general@postgresql.org; Sun, 30 Dec 2018 22:14:31 +0000 Received: from [192.168.127.1] (port=19356 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gdjLh-0000Ja-2k; Sun, 30 Dec 2018 22:14:21 +0000 Received: from [127.0.0.1] (port=53651 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gdjLg-0005oc-2Q; Sun, 30 Dec 2018 22:14:20 +0000 From: Andrew Gierth To: Rory Campbell-Lange Cc: pgsql-general@postgresql.org Subject: Re: jsonb : find row by array object attribute In-Reply-To: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> (Rory Campbell-Lange's message of "Sun, 30 Dec 2018 21:31:12 +0000") Message-ID: <87pntiu0n9.fsf@news-spur.riddles.org.uk> References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sun, 30 Dec 2018 22:14:19 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Rory" == Rory Campbell-Lange 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)