我正在使用本机查询从PostgreSQL获取分页结果,并且使用了此查询,并且遇到了以下异常:
SELECT a.*
FROM table1 a LEFT OUTER JOIN table2 b ON a.clmn1 = b.clmn1
WHERE (a.clmn3 = ?3 OR a.clmn4 ISNULL)
ORDER BY a.clmn1 DESC offset = ?1 limit = ?2
查询:
@Query(nativeQuery = true, value="select a.* from table1 a left outer join table2 b ON a.clmn1 = b.clmn1 where (a.clmn3= ?3 OR a.clmn4 isnull) order by a.clmn1 desc offset = ?1 limit = ?2")
public List<Result> getResults(int offset, int limit, int value);
例外:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "="
请提出建议。
答案 0 :(得分:0)
查询中存在语法错误。删除=
并使用命名参数,例如:
@Query(nativeQuery = true, value = "SELECT a.* FROM table1 a "
+ " LEFT OUTER JOIN table2 b"
+ " ON a.clmn1 = b.clmn1 "
+ " WHERE (a.clmn3= ?3 OR a.clmn4 IS NULL) "
+ " ORDER BY a.clmn1 DESC OFFSET :offset LIMIT :limit ")
public List<Result> getResults(@Param("offset")int offset,
@Param("limit")int limit, int value);
免责声明:未测试参数注入的工作方式,但语法应如下所示
答案 1 :(得分:0)