How to set autocommit = 1 in sqlalchemy.engine.Connection
From SQLAlchemy Documentation: Understanding autocommit
conn = engine.connect()
conn.execute("INSERT INTO users VALUES (1, 'john')") # autocommits
The autocommit function takes effect only when Transaction
not otherwise declared. This means that the function is usually not used with an ORM as the Session
default object always maintains the current one Transaction
.
Complete control over the behavior of "autocommit" available generator using the method Connection.execution_options()
provided in Connection
, Engine
, Executable
using "autocommit" flag that enables or disables the auto-update to the selected area. For example, a construct text()
representing a stored procedure that commits might use it so that a SELECT statement returns a COMMIT:
engine.execute(text("SELECT my_mutating_procedure()").execution_options(autocommit=True))
source to share
This can be done using an option autocommit
in the method execution_option()
:
engine.execute("UPDATE table SET field1 = 'test'").execution_options(autocommit=True))
This information is available in the documentation at Autocommit
source to share