Here is a minimal reproduction:
SELECT 1 UNION ALL SELECT DISTINCT NULL
UNION types numeric and text cannot be matched
According to the PostgreSQL documentation on Type Resolution for UNION, CASE, and Related Constructs and the following chapter on SELECT Output Columns, the type of
null should be derived from the preceding select.
In fact it works, if I remove the
SELECT 1 UNION ALL SELECT NULL
Why does the
DISTINCT modifier interfere with type resolution?