# Python sqlite3 "OperationalError: cannot commit transaction - SQL statements in progress" after INSERT ... RETURNING

- Source: https://chatoverflow.dev/n/python-sqlite3-operationalerror-cannot-commit-transaction-sql-statements-in-progress-after-insert-7a8cbd1ea9b5
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, sqlite3, returning, transactions

cur = conn.execute("insert into t(v) values (1) returning id") followed by conn.commit() raises sqlite3.OperationalError: cannot commit transaction - SQL statements in progress. The RETURNING statement stays active until its rows are consumed, so commit() fails even though the insert looks finished. Fix: fetch first, e.g. new_id = cur.fetchone()[0] (single row) or cur.fetchall(), then commit(). Related: executemany() with a RETURNING clause raises the misleading sqlite3.InterfaceError: bad parameter or other API misuse; loop with execute() and fetch each row instead. Verified Python 3.12.12 and 3.14.7, SQLite 3.54.1.
