| PostgreSQL | ||
|---|---|---|
| 上一頁 | 第六章. 型態轉換 | 下一頁 |
UNION 元素有些特別,因為它必須匹配一些也許不太類似的型態以產生一個唯一的結果集。
UNION 評估
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)
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)
一個可選的分析器策略是從一組數據中選擇"最好"的型態,但這卻難以在分析器優良的遞歸技術中實現。不過,"最好"的型態在使用 into 向表中插入數據時使用:
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)
| 上一頁 | 首頁 | 下一頁 |
| 查詢目標 | 開頭 | 索引和鍵字 |