summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/backends/sqlite3/base.py2
-rw-r--r--tests/regressiontests/bulk_create/tests.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 2146a7fa8a..f31d2ab3eb 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -215,7 +215,7 @@ class DatabaseOperations(BaseDatabaseOperations):
res.append("SELECT %s" % ", ".join(
"%%s AS %s" % self.quote_name(f.column) for f in fields
))
- res.extend(["UNION SELECT %s" % ", ".join(["%s"] * len(fields))] * (num_values - 1))
+ res.extend(["UNION ALL SELECT %s" % ", ".join(["%s"] * len(fields))] * (num_values - 1))
return " ".join(res)
class DatabaseWrapper(BaseDatabaseWrapper):
diff --git a/tests/regressiontests/bulk_create/tests.py b/tests/regressiontests/bulk_create/tests.py
index b4c3e7f17f..f75d983a06 100644
--- a/tests/regressiontests/bulk_create/tests.py
+++ b/tests/regressiontests/bulk_create/tests.py
@@ -59,6 +59,14 @@ class BulkCreateTests(TestCase):
"CA", "IL", "ME", "NY",
], attrgetter("two_letter_code"))
+ def test_batch_same_vals(self):
+ # Sqlite had a problem where all the same-valued models were
+ # collapsed to one insert.
+ Restaurant.objects.bulk_create([
+ Restaurant(name='foo') for i in range(0, 2)
+ ])
+ self.assertEqual(Restaurant.objects.count(), 2)
+
def test_large_batch(self):
with override_settings(DEBUG=True):
connection.queries = []