Re: indexed range queries on jsonb?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Larry White <ljw1001(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: indexed range queries on jsonb?
Date: 2014-08-26 14:33:24
Message-ID: 10736.1409063604@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Larry White <ljw1001(at)gmail(dot)com> writes:
> Logically, what I want is to be able to make queries like this:
> select * from document where ((payload->'intTest')) > 5;
> With casting, I came up with:
> select * from document where (((payload->'intTest'))::text)::integer > 5;
> But this query does not use the index according to Explain

Nope. You would have to create an index on the casted expression if you
want to use integer comparisons with the index. The raw -> expression is
of type jsonb, which doesn't sort the same as integer.

BTW, you could save a small amount of notation with the ->> operator, ie
(payload->>'intTest')::integer

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Larry White 2014-08-26 14:49:57 Re: indexed range queries on jsonb?
Previous Message Adrian Klaver 2014-08-26 13:57:52 Re: how to query against nested hstore data type