Filter objects within two seconds of one another using SQLAlchemy
- by Arrieta
Hello:
I have two tables with a column 'date'. One holds (name, date) and the other holds (date, p1, p2). Given a name, I want to use the date in table 1 to query p1 and p2 from table two; the match should happen if date in table one is within two seconds of date in table two.
How can you accomplish this using SQLAlchemy?
I've tried (unsuccessfully) to use the between operator and with a clause like:
td = datetime.timedelta(seconds=2)
q = session.query(table1, table2).filter(table1.name=='my_name').\
filter(between(table1.date, table2.date - td, table2.date + td))
Any thoughts?