-
Notifications
You must be signed in to change notification settings - Fork 257
Milestone
Description
Scenario:
await AssertQuery(
async,
ss => ss.Set<Order>().Select(o => new { OrderID = (int?)null, o.CustomerID })
.Union(ss.Set<Order>().Select(o => new { OrderID = (int?)null, o.CustomerID }))
.Union(ss.Set<Order>().Select(o => new { OrderID = (int?)o.OrderID, o.CustomerID })));This produces the following SQL:
SELECT NULL AS "OrderID", o."CustomerID"
FROM "Orders" AS o
UNION
SELECT NULL AS "OrderID", o0."CustomerID"
FROM "Orders" AS o0
UNION
SELECT o1."OrderID", o1."CustomerID"
FROM "Orders" AS o1... which fails on PG with UNION types text and integer cannot be matched. The reason is that nested unions are evaluated pairwise, and when a type cannot be inferred from either side (e.g. NULL), PG falls back to text; this causes the 2nd union to try to combine text (inferred from the two NULLs above) with int (the real type of OrderID), and this fails. This is a PostgreSQL-specific problem, the problem is described in the docs.
The fix would be to have an explicit type on the first NULL (i.e. CAST(NULL AS int)).
Note that this also affects 7.0's TPC support, which uses set operations under the hood.
Reactions are currently unavailable