Cerin
Cerin

Reputation: 64739

SQLite Equivalent to INTERVAL

I'm trying to translate the PostgreSQL query:

SELECT * FROM mytable
WHERE last_check_timestamp + (INTERVAL '1 seconds')*interval_seconds <= now()

to an equivalent query in SQLite.

What I'm getting stuck on is how to dynamically create dates/intervals based on table columns. What's the equivalent to "INTERVAL" in SQLite?

Upvotes: 7

Views: 9097

Answers (1)

mellamokb
mellamokb

Reputation: 56769

See the date and time functions for SQLite. You can say this to add 1 second to a datetime value for instance:

select datetime(last_check_timestamp, '+1 second')

A full implementation of your example query might look something like this:

select * from mytable
where datetime(last_check_timestamp,
         '+' || interval_seconds || ' second') <= datetime('now','localhost');

Demo: http://www.ideone.com/lbp3G

Upvotes: 12

Related Questions