JDBI 区间 postgresql

JDBI interval postgresql

如何正确使用此类具有日期间隔的查询

 @SqlUpdate("delete fromlogin where created < now() - ':days days' :: interval")
 void deleteOldLogin(@Bind("days") Period days);

您不能将间隔常量内的天数作为参数传递。您需要传递一个指定天数的整数,然后将其乘以所需长度的间隔。

@SqlUpdate("delete fromlogin where created < now() - :days * '1 day'::interval")

Jdbi 现在支持将 java.time.Duration 类型绑定为 intervalhttps://github.com/jdbi/jdbi/pull/670