i go first straight for my questions: Why would one rather use engine.connect() instead of engine.begin(), if the second is more reliable? Then, why is it still on the tutorial page of SQLAlchemy and everywhere in stackoverflow? Performance?
Why does engine.connect() work so inconsistently? Is the problem withing the autocommit?
My backgroundstory to this is, that i just resolved an issue. Normal SQL-queries like SELECT, CREATE TABLE and DELETE would work flawlessly when using engine.connect(). Though, using MERGE would work very inconsistently. Sometimes committing, sometimes blocking other queries, sometimes nothing. Here it is recommended to use engine.begin() for MERGE queries.
So i substituted the following code:
with engine.connect() as connection:
connection.execute('MERGE Table1 USING Table2 ON .....')
by
with engine.begin() as connection:
connection.execute('MERGE Table1 USING Table2 ON .....')
and now everything works perfectly. Inlcuding the queries of SELECT,CREATE TABLE and DELETE.
In the SQLAlchemy docs it says the second option uses transactions with a transaction-commit, but the scope of with engine.connect() does an autocommit aswell. Sorry i am a complete newbie to SQL.