Use Transactions with Isolation Levels
masterBy default, the client operates in autocommit mode. To use transactions, set the isolation_level parameter to a value other than IsolationLevel.AUTOCOMMIT (e.g., IsolationLevel.REPEATABLE_READ).
When using a with context manager:
- The transaction starts when the first SQL statement is executed.
trino.dbapi.Connection.commit()is called automatically if the block exits successfully.trino.dbapi.Connection.rollback()is called if an exception occurs.
from trino.dbapi import connect
from trino.transaction import IsolationLevel
with connect(
isolation_level=IsolationLevel.REPEATABLE_READ,
...
) as conn:
cur = conn.cursor()
cur.execute('INSERT INTO sometable VALUES (1, 2, 3)')
cur.fetchall()
cur.execute('INSERT INTO sometable VALUES (4, 5, 6)')
cur.fetchall()