summaryrefslogtreecommitdiff
path: root/test/sql/test_insert.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/sql/test_insert.py')
-rw-r--r--test/sql/test_insert.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py
index 61e0783e4..23a850f08 100644
--- a/test/sql/test_insert.py
+++ b/test/sql/test_insert.py
@@ -469,6 +469,65 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
dialect=postgresql.dialect(),
)
+ def test_heterogeneous_multi_values(self):
+ """for #6047, originally I thought we'd take any insert().values()
+ and be able to convert it to a "many" style execution that we can
+ cache.
+
+ however, this test shows that we cannot, at least not in the
+ general case, because SQL expressions are not guaranteed to be in
+ the same position each time, therefore each ``VALUES`` clause is not
+ of the same structure.
+
+ """
+
+ m = MetaData()
+
+ t1 = Table(
+ "t",
+ m,
+ Column("id", Integer, primary_key=True),
+ Column("x", Integer),
+ Column("y", Integer),
+ Column("z", Integer),
+ )
+
+ stmt = t1.insert().values(
+ [
+ {"x": 1, "y": func.sum(1, 2), "z": 2},
+ {"x": func.sum(1, 2), "y": 2, "z": 3},
+ {"x": func.sum(1, 2), "y": 2, "z": func.foo(10)},
+ ]
+ )
+
+ # SQL expressions in the params at arbitrary locations means
+ # we have to scan them at compile time, and the shape of the bound
+ # parameters is not predictable. so for #6047 where I originally
+ # thought all of values() could be rewritten, this makes it not
+ # really worth it.
+ self.assert_compile(
+ stmt,
+ "INSERT INTO t (x, y, z) VALUES "
+ "(%(x_m0)s, sum(%(sum_1)s, %(sum_2)s), %(z_m0)s), "
+ "(sum(%(sum_3)s, %(sum_4)s), %(y_m1)s, %(z_m1)s), "
+ "(sum(%(sum_5)s, %(sum_6)s), %(y_m2)s, foo(%(foo_1)s))",
+ checkparams={
+ "x_m0": 1,
+ "sum_1": 1,
+ "sum_2": 2,
+ "z_m0": 2,
+ "sum_3": 1,
+ "sum_4": 2,
+ "y_m1": 2,
+ "z_m1": 3,
+ "sum_5": 1,
+ "sum_6": 2,
+ "y_m2": 2,
+ "foo_1": 10,
+ },
+ dialect=postgresql.dialect(),
+ )
+
def test_insert_seq_pk_multi_values_seq_not_supported(self):
m = MetaData()