Aliaksei
Aliaksei

Reputation: 1457

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);

Upvotes: 3

Views: 1145

Answers (2)

Steven Schlansker
Steven Schlansker

Reputation: 38526

Jdbi now supports binding the java.time.Duration type as an interval: https://github.com/jdbi/jdbi/pull/670

Upvotes: 1

user330315
user330315

Reputation:

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")

Upvotes: 8

Related Questions