querying within json

From: Tim Dudgeon <tdudgeon(dot)ml(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: querying within json
Date: 2014-10-30 14:55:36
Message-ID: CAP=hSSfiqaxt7NFi8qUEjKrH=te_cFXDfOfZ9PYEhcJRC+oGMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Any advice on how to best query for values within json (using 9.4). I have
numeric fields within the json and want to include terms for those fields.

I've found that something like this works:

select * from atable where (json_col->>'numeric_prop')::numeric < 100;

But whilst that works:
1. seems to have unnecessary casts? The numeric _prop item is of numeric
type, but its getting retrieved as text and then cast to numeric and then
compared
2. its not going to use any index on the json_col jsonb column.

Is there a better way to do this?

Thanks
Tim

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Giuseppe Broccolo 2014-10-30 15:22:40 Re: querying within json
Previous Message Adrian Klaver 2014-10-16 20:09:40 Re: Any postgres API available to get errorcode for PQerrorMessage