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 1gdivb-0004H9-Jk for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 21:47:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdivZ-00085V-Mw for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 21:47:21 +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 1gdivZ-00085O-Bh for pgsql-general@lists.postgresql.org; Sun, 30 Dec 2018 21:47:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdivS-00019i-JO for pgsql-general@postgresql.org; Sun, 30 Dec 2018 21:47:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBULlAAD015218; Sun, 30 Dec 2018 16:47:10 -0500 From: Tom Lane 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> References: <20181230213112.3tjt7hejazwi7uqn@campbell-lange.net> Comments: In-reply-to Rory Campbell-Lange message dated "Sun, 30 Dec 2018 21:31:12 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15216.1546206430.1@sss.pgh.pa.us> Date: Sun, 30 Dec 2018 16:47:10 -0500 Message-ID: <15217.1546206430@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rory Campbell-Lange writes: > ... I can't work out how to return the whole row containing a desired > people id value. Something like this, maybe? =# select * from x where '2003'::jsonb in (select jsonb_array_elements(j #>'{people}')->'id'); j -------------------------------------------------- {"a": 3, "people": [{"id": 2003}, {"id": 2005}]} (1 row) It's not too efficient though :-( regards, tom lane