语法错误等于或接近 $1,还有一些异常 SQL 语法异常



我在 $1 或接近 $1 时收到错误语法错误,还有一些异常 sql 语法异常

"select t1.* from ( select * from employee_additional_attributes  where stwid in :stwIdList )"
            + "as t1 join ( select stwid, max(employee_additional_attribute_id) as employee_additional_attribute_id from employee_additional_attributes"
            + "where stwid in :stwIdList and mis_attribute_id in (:attributeId) and start_time <= date(:date) group by stwid )"
            + "as t2 using ( stwid, employee_additional_attribute_id" )

PostgreSQL 对参数化查询中的占位符使用$<n>语法(例如基础连接中的预准备语句)。

您的第一个 ($1) 参数中有语法错误:
(当然还有一些空格语法错误,@Jens提到)

where stwid in :stwIdList

IN的正确语法是 <expression> IN (<expression>, ...) 。不能将多个值与单个参数绑定(使用 JDBC)。如果可以绑定数组,则可以使用 <expression> = ANY (<array-expression>) 语法。

对于休眠,请参阅此相关问题(请注意查询参数周围的括号)。

最新更新