]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
allow batch with upsert if embed_values_counter is True
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Feb 2026 02:07:59 +0000 (21:07 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Feb 2026 15:09:18 +0000 (10:09 -0500)
commit1e6b43bfbab5f43d53184bb9120237a3e797f2d5
treeaab7e8aa01217fb9f3e6b802434fb6b8f149f742
parentf1201b4d1672563e8011dab2593305c269d321e9
allow batch with upsert if embed_values_counter is True

Fixed issue in the :ref:`engine_insertmanyvalues` feature where using
PostgreSQL's ``ON CONFLICT`` clause with
:paramref:`_dml.Insert.returning.sort_by_parameter_order` enabled would
generate invalid SQL when the insert used an implicit sentinel (server-side
autoincrement primary key). The generated SQL would incorrectly declare a
sentinel counter column in the ``imp_sen`` table alias without providing
corresponding values in the ``VALUES`` clause, leading to a
``ProgrammingError`` indicating column count mismatch. The fix allows batch
execution mode when ``embed_values_counter`` is active, as the embedded
counter provides the ordering capability needed even with upsert behaviors,
rather than unnecessarily downgrading to row-at-a-time execution.

Fixes: #13107
Change-Id: I382472b2cf2991b520344adea5783584e27425d0
(cherry picked from commit 574facaaf4207b952379c28673c44b62835535fb)
doc/build/changelog/unreleased_20/13107.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/provision.py
lib/sqlalchemy/dialects/postgresql/provision.py
lib/sqlalchemy/dialects/sqlite/provision.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/testing/provision.py
test/dialect/postgresql/test_on_conflict.py
test/sql/test_insert_exec.py