[sqlalchemy] Referencing DELETE table from nested statement

2014-12-03 Thread Stefan Urbanek
Hi, How can I reference a table that I am deleting from in an inner/nested statement? Here is my simplified oritinal version, no inner condition: rownum = sql.expression.over(sql.func.row_number(), partition_by=table.c.some_id,

Re: [sqlalchemy] Referencing DELETE table from nested statement

2014-12-03 Thread Michael Bayer
why don’t you use a NOT EXISTS correlated subquery? that way the subquery can refer to the outer table completely, rather than having just one column where you can call IN. On Dec 3, 2014, at 12:36 PM, Stefan Urbanek stefan.urba...@gmail.com wrote: Hi, How can I reference a table that

Re: [sqlalchemy] Referencing DELETE table from nested statement

2014-12-03 Thread Stefan Urbanek
Thanks, I used exists (reversed condition): condition = primary.c.rownum != 1 unique = sql.expression.exists([1], whereclause=condition) delete = sql.expression.delete(table, whereclause=unique) I'm still getting: