如何在 PostgreSQL 的 jdbc 中设置“5 天”(日期时间间隔)?

2023-11-25

考虑以下示例

select * from foo where time +'10 day' >current_timestamp

我想让这个查询参数化为Java,但我不知道如何设置10 day?! (字符串不起作用)


您可以传递一个 String 参数并对其进行强制转换,例如

select * from foo where (time + CAST(? AS interval)) > current_timestamp

或者传递一个 int 参数乘以固定间隔,如果您始终使用天而不是更复杂的间隔,则更好。例如。

select * from foo where (time + ? * INTERVAL '1' DAY) > current_timestamp

with a setInt范围。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 PostgreSQL 的 jdbc 中设置“5 天”(日期时间间隔)? 的相关文章

随机推荐