【发布时间】:2014-12-12 13:52:11
【问题描述】:
我需要像
这样的操作使用 alembic 语法select id from table1 where id not in (select id from table2)
在这方面似乎没有任何文档。任何指针都会有所帮助
【问题讨论】:
-
这是在迁移吗?你不能用直接的 SQL 来做吗?这个问题有帮助吗? stackoverflow.com/questions/11970555/…
我需要像
这样的操作使用 alembic 语法select id from table1 where id not in (select id from table2)
在这方面似乎没有任何文档。任何指针都会有所帮助
【问题讨论】:
要执行原始 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)')
如果只执行update和delete,不需要结果,可以使用op.execute作为快捷方式。
op.execute('delete from table2 where id in (select id from table1)')
【讨论】: