SQLAlchemy:更新from_select [英] SQLAlchemy: update from_select

查看:249
本文介绍了SQLAlchemy:更新from_select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行

UPDATE node
SET node.parent_id = node_node.parent_id,
    node.label = node_node.label
FROM node_node
WHERE node_node.child_id = node_id

使用SQLAlchemy。我确实搜索了文档,但只发现 insert()。from_select(),却没有发现 update()。from_select()。我知道我可以通过编程实现相同的目的,但是我需要尽快实现。

using SQLAlchemy. I did search the docs, and found only insert().from_select(), but no update().from_select(). I know I can achieve the same programatically, but I need it to be as fast as possible.

有可能吗?

推荐答案

假设 t_node node 表实例,而 t_node_node - node_node 表实例,请参见下面的语句。

Assuming that t_node is node Table instance, while t_node_node - node_node Table instance, see the statement below.

upd = (t_node.update()
        .values(
            parent_id = t_node_node.c.parent_id,
            label = t_node_node.c.label,
            )
        .where(t_node_node.c.child_id == t_node.c.node_id)
        )

有关插入,更新和删除文档以获取更多信息。

Read more on Inserts, Updates and Deletes documentation for more information.

这篇关于SQLAlchemy:更新from_select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆