MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_heterogeneous_multi_values

Method test_heterogeneous_multi_values

test/sql/test_insert.py:541–646  ·  view source on GitHub ↗

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

(self, paramstyle)

Source from the content-addressed store, hash-verified

539
540 @testing.variation("paramstyle", ["pg", "qmark", "numeric", "dollar"])
541 def test_heterogeneous_multi_values(self, paramstyle):
542 """for #6047, originally I thought we'd take any insert().values()
543 and be able to convert it to a "many" style execution that we can
544 cache.
545
546 however, this test shows that we cannot, at least not in the
547 general case, because SQL expressions are not guaranteed to be in
548 the same position each time, therefore each ``VALUES`` clause is not
549 of the same structure.
550
551 """
552
553 m = MetaData()
554
555 t1 = Table(
556 "t",
557 m,
558 Column("id", Integer, primary_key=True),
559 Column("x", Integer),
560 Column("y", Integer),
561 Column("z", Integer),
562 )
563
564 stmt = t1.insert().values(
565 [
566 {"x": 1, "y": func.sum(1, 2), "z": 2},
567 {"x": func.sum(1, 2), "y": 2, "z": 3},
568 {"x": func.sum(1, 2), "y": 2, "z": func.foo(10)},
569 ]
570 )
571
572 pos_par = (
573 1,
574 1,
575 2,
576 2,
577 1,
578 2,
579 2,
580 3,
581 1,
582 2,
583 2,
584 10,
585 )
586
587 # SQL expressions in the params at arbitrary locations means
588 # we have to scan them at compile time, and the shape of the bound
589 # parameters is not predictable. so for #6047 where I originally
590 # thought all of values() could be rewritten, this makes it not
591 # really worth it.
592 if paramstyle.pg:
593 self.assert_compile(
594 stmt,
595 "INSERT INTO t (x, y, z) VALUES "
596 "(%(x_m0)s, sum(%(sum_1)s, %(sum_2)s), %(z_m0)s), "
597 "(sum(%(sum_3)s, %(sum_4)s), %(y_m1)s, %(z_m1)s), "
598 "(sum(%(sum_5)s, %(sum_6)s), %(y_m2)s, foo(%(foo_1)s))",

Callers

nothing calls this directly

Calls 10

MetaDataClass · 0.90
TableClass · 0.90
ColumnClass · 0.90
assert_compileMethod · 0.80
valuesMethod · 0.45
insertMethod · 0.45
sumMethod · 0.45
fooMethod · 0.45
dialectMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected