pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ivan E. Panchenko <i.panchenko@postgrespro.ru>
To: pgsql-general@lists.postgresql.org
Subject: Re: jsonb and where clause?
Date: Tue, 28 Nov 2017 11:28:55 +0300
Message-ID: <b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru> (raw)
In-Reply-To: <20171128091807.218d7809@pennywise-btj>
References: <20171128091807.218d7809@pennywise-btj>

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




view thread (5+ messages)  latest in thread

Message-ID: <b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru>
Permalink:  ../b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru/
Also on:    postgresql.org/message-id/b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru

 · 

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: i.panchenko@postgrespro.ru
  Subject: Re: jsonb and where clause?
  In-Reply-To: <b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru>
  References: <20171128091807.218d7809@pennywise-btj> <b9341406-f066-ea08-5c0d-1a7404a95df3@postgrespro.ru>

* 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