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 1gdjcm-0006kQ-IM for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 22:32:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdjcj-0001t5-JJ for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 22:31:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdjcj-0001sh-BS for pgsql-general@lists.postgresql.org; Sun, 30 Dec 2018 22:31:57 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdjcc-0000rZ-AC for pgsql-general@postgresql.org; Sun, 30 Dec 2018 22:31:56 +0000 Received: from [192.168.127.1] (port=21765 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 1gdjcZ-0000KZ-V4; Sun, 30 Dec 2018 22:31:47 +0000 Received: from [127.0.0.1] (port=20112 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gdjcZ-0005th-9G; Sun, 30 Dec 2018 22:31:47 +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: <87pntiu0n9.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Sun, 30 Dec 2018 22:14:19 +0000") Message-ID: <87lg46tzr3.fsf@news-spur.riddles.org.uk> References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> <87pntiu0n9.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sun, 30 Dec 2018 22:31:47 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Andrew" == Andrew Gierth writes: >>>>> "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. 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)