I'm trying to write a prepared statement using a date held in JSONB. A prepared statement doesn't allow the containment operator @>
so I used the function name itself jsonb_contains
which executes, but now postgres doesn't use the gin index.
Testing in a psql session performance is excellent when I do this
select *
from tab
where jsonb_obj @> '{"date_el":"2001-01-31"}'
because it uses the gin index. But that won't parse in a prepared statement in java.
When I run this in psql:
select *
from tab
where jsonb_contains(jsonb_obj->>'date_el', '2001-01-31')
performance is very bad.
Has anyone ever had this problem?
@>
to be use in aPreparedStatement
. What is the error you get?jsonb_contains(jsonb_obj, '{"date_el":"2001-01-31"}')
. The second condition would translate tojsonb_obj -> 'date_el' @> '"2001-01-31"'