|
UNION QueriesThe UNION construct is somewhat different in that it must match up possibly dissimilar types to become a single result set. UNION Evaluation
ExamplesUnderspecified Typestgl=> SELECT text 'a' AS "Text" UNION SELECT 'b'; Text ------ a b (2 rows) Simple UNIONtgl=> SELECT 1.2 AS "Float8" UNION SELECT 1; Float8 -------- 1 1.2 (2 rows) Transposed UNIONThe types of the union are forced to match the types of the first/top clause in the union: tgl=> SELECT 1 AS "All integers" tgl-> UNION SELECT '2.2'::float4 tgl-> UNION SELECT 3.3; All integers -------------- 1 2 3 (3 rows) An alternate parser strategy could be to choose the "best" type of the bunch, but this is more difficult because of the nice recursion technique used in the parser. However, the "best" type is used when selecting into a table: tgl=> CREATE TABLE ff (f float); CREATE tgl=> INSERT INTO ff tgl-> SELECT 1 tgl-> UNION SELECT '2.2'::float4 tgl-> UNION SELECT 3.3; INSERT 0 3 tgl=> SELECT f AS "Floating point" from ff; Floating point ------------------ 1 2.20000004768372 3.3 (3 rows) |
|||||||||||||||||
With any suggestions or questions please feel free to contact us |