| 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)
| 上一页 | 首页 | 下一页 |
| 查询目标 | 开头 | 索引和键字 |