diff --git a/doc/src/sgml/typeconv.sgml b/doc/src/sgml/typeconv.sgml index c031c01ed35..aa367bb0eb0 100644 --- a/doc/src/sgml/typeconv.sgml +++ b/doc/src/sgml/typeconv.sgml @@ -1077,5 +1077,34 @@ result type is resolved as real. + +Type Resolution in a Nested Union + + + +SELECT NULL UNION SELECT NULL UNION SELECT 1; + +ERROR: UNION types text and integer cannot be matched + +This failure occurs because PostgreSQL treats +multiple UNIONs as a nest of pairwise operations; +that is, this input is the same as + +(SELECT NULL UNION SELECT NULL) UNION SELECT 1; + +The inner UNION is resolved as emitting +type text, according to the rules given above. Then the +outer UNION has inputs of types text +and integer, leading to the observed error. The problem +can be fixed by ensuring that the leftmost UNION +has at least one input of the desired result type. + + + +INTERSECT and EXCEPT operations are +likewise resolved pairwise. However, the other constructs described in this +section consider all of their inputs in one resolution step. + +