JDBI间隔PostgreSQL

Les*_*aRB 2 java postgresql jdbi

如何正确使用带有日期间隔的查询

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

a_h*_*ame 5

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

@SqlUpdate("delete fromlogin where created < now() - :days * '1 day'::interval")
Run Code Online (Sandbox Code Playgroud)