look for json key's value in jsonb

1.1k Views Asked by At

i am using criteriabuilder of jpa and i want to look for a value of a json field in a jsonb column. the jsonb looks like this :

[{"field1":"value1","field2":"value2"},{"field3":"value3","field4":"value4"}]

i started creating my predicates but i got errors.

predicates.add( builder.like(
    builder.function("JSON_EXTRACT", String.class, root1.get("jsonBColumn"),                          
    builder.literal("\"value3\"")), "%" + searchValue + "%"));

the error i am getting is

org.postgresql.util.PSQLException: ERROR: function json_extract(jsonb, character varying) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.

Can anybody help ?

1

There are 1 best solutions below

0
On

This will help:

`predicate.getExpressions().add(cb.like(cb.function("jsonb_extract_path_text", String.class, root.get("jsonBColumn"), cb.literal(this.searchKey)), "%"+ this.searchValue + "%"));