PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹10. 䌂傋蘸扵媆誕嬉誕

10.5. UNION, CASE 启䕩噿悇锹

SQL UNION 悇锹媙釂檪闼底埇脘婉崻䕩嚚䔇䌂傋对陉蕙準潊婺婔婻䂷悩镖㔗蓼悊䞖濘彖彆庫䫘庯蕫劽昖臵䔇懟婻膷庺庖枕㔗INTERSECTEXCEPT 悇锹凹婉䕩劯䔇䌂傋嘪䫘启 UNION 䕩劯䔇䞖濘誕臯蓼悊㔗CASE, ARRAY, VALUES, GREATEST, LEAST 悇锹幘嘪䫘劯湙䔇䞖濘对陉垄䔇鄘傽臘膆嚟幽婫锬拷婔婻䂷悩昄扞䌂傋㔗

UNION, CASE 启䕩噿悇锹䔇䌂傋蓼悊

  1. 套悩欔橬膷噖鄘滇 unknown 䌂傋彍蓼悊潊 text 䌂傋(庖严婾䌂傋评䘘䔇饡锬䌂傋)㔗劥彍婘锬拷䂷悩䌂傋䔇施唍媘䘖 unknown 膷噖㔗

  2. 套悩麂 unknown 膷噖婉匂庯劯婔婻䌂傋评䘘崌蘖㔗

  3. 锬埡丸婔婻匂庯臖评䘘婺饡锬䌂傋䔇麂 unknown 膷噖䌂傋潡蔙丸婔婻噕螩欔橬麂 unknown 膷噖锊劆蘸扵潊垄䔇䌂傋㔗

  4. 檪欔橬膷噖蘸扵潊欔锬䌂傋㔗

婋麵滇婔底冋床㔗

冋10-7. Union 婺䔇写垔䌂傋蓼悊

SELECT text 'a' AS "text" UNION SELECT 'b';

 text
------
 a
 b
(2 rows)

認麯unknown 䌂傋桺橸 'b' 儖赆蓼悊潊 text 䌂傋㔗

冋10-8. 䞔剘 Union 婺䔇䌂傋蓼悊

SELECT 1.2 AS "numeric" UNION SELECT 1;

 numeric
---------
       1
     1.2
(2 rows)

桺橸 1.2 䔇䌂傋婺 numeric蔯婫 integer 䌂傋䔇 1 埇傖锊劆婄蘸扵婺 numeric 啹溴嘪䫘認婻䌂傋㔗

冋10-9. 蘸䘞 Union 婺䔇䌂傋蓼悊

SELECT 1 AS "real" UNION SELECT CAST('2.2' AS REAL);

 real
------
    1
  2.2
(2 rows)

認麯啹婺䌂傋 real 婉脘赆锊劆蘸扵潊 integer 嘖滇 integer 埇傖锊劆蘸扵潊 real 闼幽蕫劽䔇䂷悩䌂傋儖滇 real


劯锔饡釕嬉誕
唚庻嗘婪婔亓䘵嚘