我无法用sqlAlchemy做这样的事情:
DELETE a FROM a INNER JOIN b ON b.`aId` = a.`Id` WHERE `b`.`xxx` = ?;
正如这里的帖子:SQLAlchemy: Create delete query using self-join on MySQL
所以我现在这样做:
session.execute('DELETE a FROM a INNER JOIN b ON b.`aId` = a.`Id` WHERE `b`.`xxx` = %d;'%xxx)
但它只是让我很烦恼:sql注入事物等等.
最佳答案
如果您阅读documentation for
session.execute
,您将看到您应该执行以下操作:
session.execute(
'DELETE a FROM a INNER JOIN b ON b.`aId` = a.`Id` WHERE `b`.`xxx` = :param',{"param": 5}
)