0

My query is:

SELECT id
FROM person
WHERE authority_right = ARRAY[1,2]

authority_right is integer array. My goal is to find people who have authority_right exactly equal to [1,2], not [1] and not [2]. This query is executed successfully in console, but a validation error occurs when I launch my application with @Query using the exact same code. Error occurs in this area: ARRAY[1,2]. Message in logs:

expecting CLOSE_BRACKET, found ','

Message in editor:

<expression>, <operator>, GROUP, HAVING or ORDER expected, got '{'

I also tried using INT{1, 2} and some combinations of brackets, but I haven't succeed. How can I make it work?

stakeika
  • 55
  • 1
  • 8
  • `right` is a reserved keyword. So you need double quotes: `where "right" = ...`. If you are using a native query in JPQL, the `ARRAY[...]` syntax should work. Alternatively use a string constant for the array `where "right" = '{1,2}'` –  Apr 10 '23 at 11:01
  • @a_horse_with_no_name I'm sorry for confusion, the field name is actually `authority_right`, I shortened it intentionally in the question. I've tried your suggestion `where "right" = '{1,2}'`, unfortunately it produces another validation error `person is not mapped` – stakeika Apr 10 '23 at 11:16

0 Answers0