sqlalchemy core将选择语句转换为更新语句
现在,我正在使用SQLalchemy Core(不是ORM)1.4,并且我有两个语句:
stmt1 = sa.select(groups).where(groups.c.id == group_id)
stmt2 = sa.update(groups).where(groups.c.id == group_id)
我想知道是否有一种方法可以将 stmt1
转换为 stmt2
stmt2 因为我想构建这样的声明:
# doing something to convert stmt1 to stmt2. is it possible?
stmt2 = stmt2.values(**my_dict)
谢谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到答案,所以我在这里发布。
首先,我问是否可以将在更新使用sqlalchemy core的位置进行选择。
可以使用,但是它返回元组,因为我们通常选择或与一个或多个表一起选择或加入。
我的目的是获取一个必须更新的记录。
因此,我从更新语句中得出了Select语句:
现在我不必传递非常相似的两个语句。谢谢。
I found an answer by myself, so I post here.
At first, I asked if I can convert
select where
toupdate where
using SQLAlchemy core.It's possible using Select().get_final_froms, but it returns a tuple because we usually select or join with one or more tables.
My purpose was fetching one record which has to be updated.
Thus, I derived the select statement from update statement like this:
Now I don't have to pass very similar two statements. Thank you.