Filter objects within two seconds of one another using SQLAlchemy

Posted by Arrieta on Stack Overflow See other posts from Stack Overflow or by Arrieta
Published on 2010-05-28T22:56:40Z Indexed on 2010/05/28 23:02 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about database