summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-06-04 19:45:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-06-04 19:45:45 -0400
commitb2cd9aca54d1625dde31abebf7f11149c9b7c636 (patch)
tree1ee7b31a3c549d8410875113932c1f1cc85cd94c /lib/sqlalchemy/sql/compiler.py
parent3874d2576dc536b54af9f5525aff1fe59f4f00d3 (diff)
downloadsqlalchemy-b2cd9aca54d1625dde31abebf7f11149c9b7c636.tar.gz
don't enable "fast insert executemany" for ON CONFLICT etc
Fixed issue where using the PostgreSQL "INSERT..ON CONFLICT" structure would fail to work with the psycopg2 driver if it were used in an "executemany" context along with bound parameters in the "SET" clause, due to the implicit use of the psycopg2 fast execution helpers which are not appropriate for this style of INSERT statement. Additional checks to exclude this kind of statement from that particular extension have been added. Fixes: #6581 Change-Id: I3d6169e7e188dc087d1d1bfba9a42162db183265
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 734e65492..220a0fa99 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -3588,7 +3588,14 @@ class SQLCompiler(Compiled):
[value for c, expr, value in crud_params]
)
text += " VALUES (%s)" % insert_single_values_expr
- if toplevel:
+ if toplevel and insert_stmt._post_values_clause is None:
+ # don't assign insert_single_values_expr if _post_values_clause
+ # is present. what this means concretely is that the
+ # "fast insert executemany helper" won't be used, in other
+ # words we won't convert "executemany()" of many parameter
+ # sets into a single INSERT with many elements in VALUES.
+ # We can't apply that optimization safely if for example the
+ # statement includes a clause like "ON CONFLICT DO UPDATE"
self.insert_single_values_expr = insert_single_values_expr
if insert_stmt._post_values_clause is not None: