SQL"在#34;中的Alembic语法操作者

时间:2014-12-12 13:52:11

标签: python alembic

我需要使用alembic语法进行类似

的操作
select id from table1 where id not in (select id from table2)

此处似乎没有任何文档。任何指针都会有所帮助

1 个答案:

答案 0 :(得分: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)')