我知道SQL标准允许列中的多个NULL值是UNIQUE约束的一部分.
我不明白为什么UNION构造(至少在PostgreSQL中)将NULL值视为相同.例如:
$ select * from tmp_a;
a | b
---+---
a | b
a |
|
(3 rows)
$ select * from tmp_b;
a | b
---+---
a | c
a |
|
(3 rows)
$ select a, b from tmp_a union select a, b from tmp_b order by 1, 2;
a | b
---+---
a | b
a | c
a |
|
(4 rows)
Run Code Online (Sandbox Code Playgroud)