【问题标题】:Alembic syntax for SQL "in" operatorSQL“in”运算符的 Alembic 语法
【发布时间】:2014-12-12 13:52:11
【问题描述】:

我需要像

这样的操作使用 alembic 语法
select id from table1 where id not in (select id from table2)

在这方面似乎没有任何文档。任何指针都会有所帮助

【问题讨论】:

标签: python alembic


【解决方案1】:

要执行原始 SQL 查询,请使用 op.get_bind() 获取 Connection,然后使用它的 execute 方法。

c = op.get_bind()
result = c.execute('select id from table1 where id not in (select id from table2)')

如果只执行updatedelete,不需要结果,可以使用op.execute作为快捷方式。

op.execute('delete from table2 where id in (select id from table1)')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多