0

I have a jsonb column in my posgtgres table the json is of structure : {'alias':["name1","name2","name"....]}

I have written the Postgres query to check if the array in the JSON object contains the name.

select * from public.table t where json_col->'alias' ? 'name'

this works on pgAdmin

But same doesn't work in JPA

My code

@Query(value = "select * from public.table t where json_col->'alias' ? :name" ,nativeQuery = true)
    Table findUsingName(@Param("name") String name);

This throws an error : 'Mixing of ? parameters and other forms like ?1 is not supported!'

I understand this error is due to the fact ? is also used by JPA is different sense...

Can anyone help me in the JPA Query

1
  • Try ?? instead. I think the JDBC driver will detect that's an "escaped" ? operator. Commented Jan 14, 2021 at 7:40

2 Answers 2

1

I don't know what the ? operator does, but you should use the named variant of the operator as a ? in JDBC is used to define a parameter.

Sign up to request clarification or add additional context in comments.

Comments

0

Found the postgres function for '?' i.e. jsonb_exists_any(company_alias->'alias',ARRAY[:name])

2 Comments

The disadvantage of using the function is that it can't make use of an index if you need that for performance reasons.
I tried ?? but this the error: 'Mixing of? parameters and other forms like ? 1 is not supported!' I had no other option

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.