I want to use 2 columns in where in
clause in PostgreSQL 13.2. I tested it by executing the following query
select * from collision_danger_pair_contexts
where
(first_target_id, second_target_id)
in
( ('63efc3d9-8fc7-4b39-a9ce-b926dae4e104', '63efc3d9-8fc7-4b39-a9ce-b926dae4e105') );
it worked.
Now the question is how to achieve the same using Spring Data JPA. I've tried the following query
@Query(
nativeQuery = true,
value = """
SELECT * FROM collision_danger_pair_contexts ctx
WHERE (ctx.first_target_id, ctx.second_target_id) IN (:targetIds)
"""
)
List<CollisionDangerPairContext> findByTarget1IdAndTarget2Id(@Param("targetIds") List<UUID[]> targetIds);
where targetIds
contains a list of arrays of UUIDs. The length of each array is 2.
But I've got the error:
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: record = bytea
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Before I ran the query my intuition told me that I was to optimistic hoping that it would work, but I don't understand how and where I should do the "casting".
I've also tried to change the parameter to
List<List<UUID>> targetIds
but it didn't work either. What is the correct syntax/casting ?
The best way for me would be using
List<org.apache.commons.lang3.tuple.ImmutablePair<UUID, UUID>> targetIds