What is the difference between executing raw SQL on the SQLAlchemy engine and the session? Specifically against a MSSQL database.
engine.execute('DELETE FROM MyTable WHERE MyId IN(1, 2, 3)')
versus
session.execute('DELETE FROM MyTable WHERE MyId IN(1, 2, 3)')
I've noticed that executing the SQL on the session, cause MSSQL to 'hang'.
Perhaps someone has an idea on how these two executions are different, or perhaps someone can point me where to further investigate.
echo=True
on yourcreate_engine
call and every query will be printed out. Check what are the differences between the two. - Dekelengine.execute(..)
might create a new transaction, whereassession.execute(..)
uses the current transaction of the session. I guess the difference might be related to that. Try to enableSQL
logging as per @Dekel's comment to understand why? or performsession.commit()
orsession.rollback()
just beforesession.execute
to test this hypothesis. - van