I have a native query in Spring Boot as such:
@Query(value = "SELECT t.* FROM Transaction t WHERE " +
"t.datetime >= TO_TIMESTAMP(?1,'YYYY-MM-ddTHH:MI') " +
"AND t.datetime < TO_TIMESTAMP(?2,'YYYY-MM-ddTHH:MI') " +
"AND (t.location_1 = ?3 or ?3 is null) " +
"LIMIT ?4",
nativeQuery = true)
List<Transaction> findBySearchTerms(@Param("fromDateTime") String fromDateTime,
String toDateTime,
Integer location1,
Integer maxCount
);
For the location1, it may be null. When i run this query with location1 null, it returns the error message: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = bytea
After which i tried casting on parameter 3:
"AND (?3 is null or t.location_1 = cast(?3 as bigint)) " +
It also results in an error: org.postgresql.util.PSQLException: ERROR: cannot cast type bytea to bigint.
I have searched for similar questions on stackoverflow and followed some of the recommendations but it still does not work. Any ideas?