【发布时间】:2021-05-19 22:20:11
【问题描述】:
我对spring boot的SQL函数不熟悉。谁能检查我的 spring boot 查询是否正确?
我创建了一个 PostgreSQL 函数并用 spring boot 实现了它。 但是当我调用 JPA 查询时出现错误。下面我附上了SQL函数和JPA查询
PostgreSQL 函数 - 工作正常
select pulse.fn_get_ticket_details_json(''::text,null::date,null::date,''::text)
Spring 启动查询
@Query(value = "select pulse.fn_get_ticket_details_json(''::text,null::date,null::date,''::text)", nativeQuery = true)
JsonObject SearchData();
错误信息
ERROR: syntax error at or near ":"
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
Position: 44
【问题讨论】:
-
冒号被 JPA 用于替换变量。你能用
\\:转义冒号:吗?所以,你的::text,应该是\\:\\:text, -
@gtiwari333 显示错误 @Query(value = "select pulse.fn_get_ticket_details_json(''::text,null::date,null::date,''\\:\\:text)" , nativeQuery = true)
-
你必须为每次出现
:做这个 -
@gtiwari333 我添加了一个截图。请检查一下。
标签: spring postgresql spring-boot spring-data-jpa