MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_inserts_w_all_nulls

Method test_inserts_w_all_nulls

test/sql/test_insert_exec.py:1616–1645  ·  view source on GitHub ↗

this test is geared towards the INSERT..SELECT VALUES case, where if the VALUES have all NULL for some column, PostgreSQL assumes the datatype must be TEXT and throws for other table datatypes. So an additional layer of casts is applied to the SELECT p0,p1, p2... part of

(
        self, connection, metadata, sort_by_parameter_order, datatype
    )

Source from the content-addressed store, hash-verified

1614 argnames="datatype",
1615 )
1616 def test_inserts_w_all_nulls(
1617 self, connection, metadata, sort_by_parameter_order, datatype
1618 ):
1619 """this test is geared towards the INSERT..SELECT VALUES case,
1620 where if the VALUES have all NULL for some column, PostgreSQL assumes
1621 the datatype must be TEXT and throws for other table datatypes. So an
1622 additional layer of casts is applied to the SELECT p0,p1, p2... part of
1623 the statement for all datatypes unconditionally. Even though the VALUES
1624 clause also has bind casts for selected datatypes, this NULL handling
1625 is needed even for simple datatypes. We'd prefer not to render bind
1626 casts for all possible datatypes as that affects other kinds of
1627 statements as well and also is very verbose for insertmanyvalues.
1628
1629
1630 """
1631 t = Table(
1632 "t",
1633 metadata,
1634 Column("id", Integer, Identity(), primary_key=True),
1635 Column("data", datatype),
1636 )
1637 metadata.create_all(connection)
1638 result = connection.execute(
1639 insert(t).returning(
1640 t.c.id,
1641 sort_by_parameter_order=bool(sort_by_parameter_order),
1642 ),
1643 [{"data": None}, {"data": None}, {"data": None}],
1644 )
1645 eq_(set(result), {(1,), (2,), (3,)})
1646
1647 @testing.variation("pk_type", ["autoinc", "clientside"])
1648 @testing.variation("add_sentinel", ["none", "clientside", "sentinel"])

Callers

nothing calls this directly

Calls 8

TableClass · 0.90
ColumnClass · 0.90
IdentityClass · 0.90
insertFunction · 0.90
eq_Function · 0.90
create_allMethod · 0.80
executeMethod · 0.45
returningMethod · 0.45

Tested by

no test coverage detected