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
)
| 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"]) |