如何将 TIMESTAMPDIFF 添加到 SqlSoup 查询?

发布于 11-28 16:54 字数 576 浏览 3 评论 0原文

我有一个正在运行并使用 SqlSoup 的报告程序,并且现在通过 SqlSoup 调用生成了整个查询(MySqL 函数 TIMESTAMPDIFF 除外)。

实际的 SQL 短语应该是

TIMESTAMPDIFF(PERIOD, start_time, end_time) <= 60

我尝试过的

from sqlalchemy.sql.expression import func

和一个 where 子句短语(使用 rc 对数据库和表的引用)

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

这可以编译,但登录后会显示 PERIOD作为 %s 和参数 PERIOD 下面,这似乎不起作用。

对于使用 SqlSoup 执行此操作有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜扑2024-12-05 16:54:28

在这种情况下,sqlalchemy.text() 是你的朋友:-)

尝试:

sqlalchemy.func.TIMESTAMPDIFF(sqlalchemy.text('PERIOD'),rc.start_time,rc.end_time) <= 60)

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

Try:

sqlalchemy.func.TIMESTAMPDIFF(sqlalchemy.text('PERIOD'),rc.start_time,rc.end_time) <= 60)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文