Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add TIMESTAMPDIFF to SqlSoup query?

I have a reporting program running and using SqlSoup and have the entire query generated now by SqlSoup calls except for the MySqL Function TIMESTAMPDIFF.

The actual SQL phrase should be

TIMESTAMPDIFF(PERIOD, start_time, end_time) <= 60

I tried

from sqlalchemy.sql.expression import func

and a where-clause phrase (with rc a reference to the database and table)

where = and_(where, func.TIMESTAMPDIFF('PERIOD',rc.start_time,rc.end_time) <= 60)

This compiles, but with logging on it shows the PERIOD as %s and then a parameter PERIOD below, which does not seem to work.

Any ideas for doing this with SqlSoup?

like image 248
Mark McWiggins Avatar asked Aug 09 '11 00:08

Mark McWiggins


1 Answers

sqlalchemy.text() is your friend in this case :-)

Try:

sqlalchemy.func.TIMESTAMPDIFF(sqlalchemy.text('PERIOD'),rc.start_time,rc.end_time) <= 60)
like image 146
epegzz Avatar answered Sep 23 '22 17:09

epegzz