0

i need the alembic syntax for an operation like

select id from table1 where id not in (select id from table2)

there doesn't seem to be any documentation anywhere on this. any pointers would be helpful

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Jules
  • 1,071
  • 2
  • 18
  • 37
  • Is this in a migration? Could you not do it with straight SQL? Does this question help? http://stackoverflow.com/questions/11970555/modify-data-as-part-of-an-alembic-upgrade – WayneC Dec 12 '14 at 13:54

1 Answers1

1

To execute raw SQL queries, use op.get_bind() to get a Connection, then use it's execute method.

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

If you are only performing update and delete and don't need results, you can use op.execute as a shortcut.

op.execute('delete from table2 where id in (select id from table1)')
davidism
  • 121,510
  • 29
  • 395
  • 339