Answer the question
In order to leave comments, you need to log in
How to make an index on a JSONB field in PostgreSQL?
There is a jsonb properties field .
Some entries in properties have a price object .
That is, there is such a json object:
{
price: {
id: 222,
val: 150
}
}
SELECT * FROM "TABLE_NAME" WHERE (properties #>> '{price, val}')::int BETWEEN '100' AND'200'
CREATE INDEX price_btree_idx ON estates USING btree (((properties -> 'price') -> 'val'))
CREATE INDEX properties_gin_idx ON estates USING gin (properties jsonb_path_ops)
Answer the question
In order to leave comments, you need to log in
I'll be a necroposter
Apparently you need to create an index as described here - https://stackoverflow.com/questions/36075918/postg...
i.e. CREATE INDEX price_btree_idx ON estates ((((properties -> 'price') -> ' val'))::int)
Unfortunately, I don't have postgresql at hand to check, but try to make a functional index on the price field, I think there should be such an opportunity.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question