| PostgreSQL 8.0.12 Documentation | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Chapter 10. Type Conversion | Fast Forward | Next |
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. The CASE and ARRAY constructs use the identical algorithm to match up their component expressions and select a result data type.
UNION, CASE, and ARRAY Type Resolution
If all inputs are of type unknown, resolve as type text (the preferred type of the string category). Otherwise, ignore the unknown inputs while choosing the result type.
If the non-unknown inputs are not all of the same type category, fail.
Choose the first non-unknown input type which is a preferred type in that category or allows all the non-unknown inputs to be implicitly converted to it.
Convert all inputs to the selected type.
Some examples follow.
Example 10-7. Type Resolution with Underspecified Types in a Union
SELECT text 'a' AS "text" UNION SELECT 'b'; text ------ a b (2 rows)
Here, the unknown-type literal 'b' will be resolved as type text.
No comments could be found for this page.
Please use this form to add your own comments regarding your experience with particular features of PostgreSQL, clarifications of the documentation, or hints for other users. Please note, this is not a support forum, and your IP address will be logged. If you have a question or need help, please see the faq, try a mailing list, or join us on IRC. Note that submissions containing URLs or other keywords commonly found in 'spam' comments may be silently discarded. Please contact the webmaster if you think this is happening to you in error.
In order to submit a comment, you must have a community account.
* denotes required field