0

Имеется приложение на 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
6
  • Это где такой запрос?
    – Roman C
    18 авг 2021 в 16:26
  • В логах. Или Вы про запрос в аннотации?
    – Montana
    18 авг 2021 в 16:30
  • В логах это не видно.
    – Roman C
    18 авг 2021 в 16:43
  • В пропертях указал spring.jpa.show-sql=true, после этого в консоли появился запрос
    – Montana
    18 авг 2021 в 16:48
  • В общем покопался, проблема возникает только в том случае, если в качестве любого из параметров передавать null
    – Montana
    18 авг 2021 в 16:53

1 ответ 1

0

В общем проблему решил создав функцию в БД, которая в качестве аргумента принимает строку, в строке уже передаю json. С передачей в БД null значений, увы, так и не смог найти решение.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.