这是我的jdbc方法
@Override
@SqlQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_CAMPAIGN_ID + " = :campaignId AND " + COLUMN_STATUS
+ " = 0 AND " + COLUMN_STAGE_ID + " IS NULL AND " + COLUMN_MODIFICATION_DATE
+ " < NOW() - INTERVAL '<timeInterval>'")
List<Idea> getDraftIdeasBeforeTime(@Bind("campaignId") long campaignId,
@Define("timeInterval") String timeInterval);
在执行时,出现以下错误
ERROR [2021-10-22 10:06:00,041] com.addons.advanced.jobs.DraftIdeasJob: Exception received while trying to delete draft ideas : org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type timestamp without time zone
Position: 127 [statement:"SELECT * FROM ideas WHERE campaign_id = :campaignId AND status = 0 AND stage_id IS NULL AND modification_date < NOW() - INTERVAL '<timeInterval>'", located:"SELECT * FROM ideas WHERE campaign_id = :campaignId AND status = 0 AND stage_id IS NULL AND modification_date ", rewritten:"/* IdeasDaoJdbi.getDraftIdeasBeforeTime */ SELECT * FROM ideas WHERE campaign_id = ? AND status = 0 AND stage_id IS NULL AND modification_date ", arguments:{ positional:{}, named:{campaignId:10}, finder:[]}]
正如您所看到的,post location,它只考虑到... AND modification_date
之前的内容,而忽略之后的内容。
为什么会发生这种情况?
您需要在查询中转义<
(更改为\<
)符号,因为它与模板引擎使用的符号相同。
编辑:对于更具体的答案,问题在
" < NOW() - INTERVAL '<timeInterval>'"
需要是
" \< NOW() - INTERVAL '<timeInterval>'"