Frank van Vugt <ftm(dot)van(dot)vugt(at)foxi(dot)nl> writes:
>> UNION requires assignment of a definite type to the inputs, because
>> otherwise there's no certainty that we know how to identify distinct
>> and non-distinct values. The alternative to assigning TEXT is to
>> reject the inner UNION outright :-(
> But in a UNION ALL the distinctiveness isn't an issue, is it?
True. We do not currently distinguish UNION from UNION ALL as far as
datatype assignment rules go (INTERSECT/EXCEPT also act just the same).
In theory we could allow an output column of UNION ALL to remain
"unknown". I'm not sure if it'd be a good idea to do so or not. It'd
make this particular example work the way you want, but otherwise it
seems like making UNION ALL a special case would be a bit of a wart on
the type system.
regards, tom lane