Имеется приложение на Spring Boot'е, БД PostgreSQL. Пытаюсь отправить следующий запрос в БД:
@Query(value = "select ROW_number() over() as id" +
", count(P.\"Id\") AS winsCount" +
", sum(P.\"Price\") AS contractSum" +
", count(H.\"Id\") AS guarCount" +
", sum(H.\"Value\") as guarSum" +
" from \"Protocols\" AS P" +
" left join \"HtmlItemsValues\" AS H" +
" ON P.\"HtmlItemId\" = H.\"HtmlItemId\"" +
" AND H.\"Type\" = 2" +
" WHERE (P.\"Price\" <= :p1 or :p1 is null)" +
" AND (P.\"Price\" >= :p2 or :p2 is null)" +
" AND (H.\"Value\" <= :p3 or :p3 is null)" +
" AND (H.\"Value\" >= :p4 or :p4 is null)" +
" AND (P.\"Dt\" <= :p5 or :p5 is null)" +
" AND (P.\"Dt\" >= :p6 or :p6 is null)", nativeQuery = true)
WinInfo getFilteredInfo(@Param("p1") Long minContrSum, @Param("p2") Long maxContrSum, @Param("p3") Long guarMinSum
, @Param("p4") Long guarMaxSum
, @Param("p5") LocalDate dateBefore, @Param("p6") LocalDate dateAfter);
В БД уходит следующий запрос:
select ROW_number() over() as id, count(P."Id") AS winsCount, sum(P."Price") AS contractSum, count(H."Id") AS guarCount, sum(H."Value") as guarSum from "Protocols" AS P left join "HtmlItemsValues" AS H ON P."HtmlItemId" = H."HtmlItemId" AND H."Type" = 2 WHERE (P."Price" <= ? or ? is null) AND (P."Price" >= ? or ? is null) AND (H."Value" <= ? or ? is null) AND (H."Value" >= ? or ? is null) AND (P."Dt" <= ? or ? is null) AND (P."Dt" >= ? or ? is null)
Соответственно Spring JPA не видит параметры, передаваемые в запрос, и кидает исключение:
org.postgresql.util.PSQLException: ERROR: operator does not exist: double precision <= bytea