The UNION construct is somewhat different in that it must match up possibly dissimilar types to become a single result set.
UNION 構成は、似ていない可能性がある型を1つの結果の集合になるように 合わせなければならないという点で少し異なっています。
UNION の評価
Check for identical types for all results.
全ての結果が同一の型かどうか点検します。
Coerce each result from the UNION clauses to match the type of the first SELECT clause or the target column.
UNION 句の各結果を最初の SELECT 句または対象カラムの型に合うように 強制します。
tgl=> SELECT text 'a' AS "Text" UNION SELECT 'b'; Text ---- a b (2 rows)
tgl=> SELECT 1.2 AS Float8 UNION SELECT 1; Float8 ------ 1 1.2 (2 rows)
The types of the union are forced to match the types of the first/top clause in the union:
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)