Search code examples
javapostgresqljdbi

JDBI interval postgresql


How properly use such query with date intervals

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

Solution

  • You can't pass the number of days inside an interval constant as a parameter. You need to pass an integer specifying your number of days, then multiply that with an interval of the desired length.

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