SQL UNION constructs must match up possibly dissimilar types to become a single result set. The resolution algorithm is applied separately to each output column of a union query. The INTERSECT and EXCEPT constructs resolve dissimilar types in the same way as UNION. A CASE construct also uses the identical algorithm to match up its component expressions and select a result data type.
UNION and CASE Type Resolution
If all inputs are of type unknown, resolve as type text (the preferred type for string category). Otherwise, ignore the unknown inputs while choosing the type.
If the non-unknown inputs are not all of the same type category, fail.
If one or more non-unknown inputs are of a preferred type in that category, resolve as that type.
Otherwise, resolve as the type of the first non-unknown input.
Coerce all inputs to the selected type.