Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Equivalent to INTERVAL

Tags:

sql

sqlite

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?

like image 859
Cerin Avatar asked Oct 07 '11 03:10

Cerin


1 Answers

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

like image 141
mellamokb Avatar answered Sep 30 '22 01:09

mellamokb