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?
sqlalchemy.text()
is your friend in this case :-)
Try:
sqlalchemy.func.TIMESTAMPDIFF(sqlalchemy.text('PERIOD'),rc.start_time,rc.end_time) <= 60)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With