Re: jsonb and comparison operators

From: Oleg Bartunov <obartunov(at)gmail(dot)com>
To: Joe Van Dyk <joe(at)tanga(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: jsonb and comparison operators
Date: 2014-09-03 08:14:36
Message-ID: CAF4Au4wnOYpMtro0ZM3=h5rpZ3w=XGx_-Q2fsCz97-+iO8_YNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jsquery (https://github.com/akorotkov/jsquery) should works for you.

On Wed, Sep 3, 2014 at 8:38 AM, Joe Van Dyk <joe(at)tanga(dot)com> wrote:

> Is it possible to get this query (or a similar one) to use an index?
>
> I want to return all rows that have a value of less than 10. I have
> arbitrary keys I want to check (not just 'a').
>
> drop table if exists test;
>
> create table test (j jsonb);
>
> insert into test select json_build_object('a', i)::jsonb from
> generate_series(1, 100000) i;
> create index on test using gin(j);
>
> vacuum analyze test;
>
>
>
> select * from test where (j->>'a')::int < 10;
>
> I tried
> select * from test where j->'a' < 10::json::jsonb;
> but didn't seem to use the index.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vinayak 2014-09-03 13:04:46 || operator
Previous Message Joe Van Dyk 2014-09-03 05:06:45 Re: jsonb and comparison operators