summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2022-01-24 11:36:13 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-01-24 20:51:32 +0100
commitc27932ec938217d4fbb0adad23c0d0708f83f690 (patch)
treef54127fb771dd9e0da495c6862aa3ebcf4fad7e3
parent4ac0bf6acd6f82036a82f23705b14cce4ab28cb0 (diff)
Fixed #33460 -- Used VALUES clause for insert in bulk on SQLite.
SQLite 3.7.11 introduced the ability to use multiple values directly. SQLite 3.8.8 made multiple values not subject to the SQLITE_LIMIT_COMPOUND_SELECT (500).
-rw-r--r--django/db/backends/sqlite3/operations.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index 34a7251eea..c1a6da4e5d 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -337,10 +337,9 @@ class DatabaseOperations(BaseDatabaseOperations):
return bool(value) if value in (1, 0) else value
def bulk_insert_sql(self, fields, placeholder_rows):
- return " UNION ALL ".join(
- "SELECT %s" % ", ".join(row)
- for row in placeholder_rows
- )
+ placeholder_rows_sql = (', '.join(row) for row in placeholder_rows)
+ values_sql = ', '.join(f'({sql})' for sql in placeholder_rows_sql)
+ return f'VALUES {values_sql}'
def combine_expression(self, connector, sub_expressions):
# SQLite doesn't have a ^ operator, so use the user-defined POWER