我正在使用本机查询从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 "="
请建议。
最佳答案
查询中存在语法错误。删除=
并首选命名参数,如:
@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);
免责声明:没有测试参数注入的工作方式,但是语法应该如下