Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJbGJ-0003pT-Dw for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 08:29:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJbGI-0002Zq-KG for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 08:29:02 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJbGI-0002Zb-9a for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 08:29:02 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eJbGD-0003cK-TQ for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 08:29:01 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 4B9F421C1D26 for ; Tue, 28 Nov 2017 11:28:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from [192.168.1.142] (ppp109-252-62-180.pppoe.spdop.ru [109.252.62.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 20B6221C1AA1 for ; Tue, 28 Nov 2017 11:28:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1511857736; bh=wrhJmCTbxa+y8HIip4fbp49bMH7gn2PXl8frXw7pS70=; h=Subject:To:References:From:Date:In-Reply-To; b=gEC8tOWwlT5W2SFzTnIfbYwUlUrAlR0+oMiOGOQhVvP1eSAaDAzH6ypkdDtDc4h/p 64osj2acBAUNkI5zybPlSiKYy8o21gra810dxn7EcB7C+PtGIi8QU/fhPdvTRqbv30 pP7/0Cid3lxsAmNlzSEM3EX9/aDK9/J2bAEgnu+Q= Subject: Re: jsonb and where clause? To: pgsql-general@lists.postgresql.org References: <20171128091807.218d7809@pennywise-btj> From: "Ivan E. Panchenko" Message-ID: Date: Tue, 28 Nov 2017 11:28:55 +0300 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171128091807.218d7809@pennywise-btj> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Bjorn, 28.11.2017 11:18, Bjorn T Johansen пишет: > Hi. > > Just starting to look at how to use jsonb columns and I have a question. I have found out that I can use the following to search for a value inside > the jsonb column: > > select * from orders where info ->> 'customer' = 'John Doe' (where info is the jsonb column) > > > But what if the jsonb column contains an json array, how can I search then? > > info -> [ { "customer" : "John Doe" } ] If you know the index in array, you can search like info->0->>'customer' If you want to search in any array element, you need to use JSQUERY extension, see https://github.com/postgrespro/jsquery > > > btw, using PostgreSQL 9.6 but will be moving to 10 soon. > > > Regards, > > BTJ > Regards, Ivan