带有参数的 PostgreSQL NativeQuery - org.postgresql.util.PSQLException:错误:“$1”处或附近的语法错误
每当我尝试使用参数执行 nativeQuery 时,我都会看到以下错误。
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
正在使用的查询和 repo 函数如下
private String queryStr = "SELECT * FROM schema1.txn " +
"WHERE stat = 'Shipped' " +
"AND id IN :idList\\:\\:text[] " +
"AND issue_dt < NOW() - :ageToExpire\\:\\:interval";
@Query(value = queryStr, nativeQuery = true)
List<txn> findTxns(
@Param("idList") String idList,
@Param("ageToExpire") String ageToExpire
);
,findTxns
调用看起来像这样,所以
.findTxns("('ID1','ID2','ID3')", "'10 days'")
我不确定为什么我仍然看到上述错误。我将字符串参数转换为它们各自的文本列表和间隔类型,但 Postgres 似乎不同意这一点。我见过类似的问题,但我似乎无法让任何标记的解决方案在我的案例中发挥作用;我尝试将查询隔离为仅使用一个参数,但这并不能解决任何问题。
I'm seeing the below error whenever I try and execute a nativeQuery with params.
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
The query being used and repo function is below
private String queryStr = "SELECT * FROM schema1.txn " +
"WHERE stat = 'Shipped' " +
"AND id IN :idList\\:\\:text[] " +
"AND issue_dt < NOW() - :ageToExpire\\:\\:interval";
@Query(value = queryStr, nativeQuery = true)
List<txn> findTxns(
@Param("idList") String idList,
@Param("ageToExpire") String ageToExpire
);
And the findTxns
call looks like so
.findTxns("('ID1','ID2','ID3')", "'10 days'")
I'm unsure as to why I'm still seeing the above error. I'm casting the string params to their respective text list and interval types but Postgres doesn't seem to agree with that. I've seen similar issues but I can't seem to get any of the marked resolutions working in my case; I've tried isolating the query to just use one param but that isn't resolving anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论