gpt4 book ai didi

postgresql - 比较两个可能为空的字段

转载 作者:行者123 更新时间:2023-11-29 11:30:49 25 4
gpt4 key购买 nike

如果 a.unitnum 和 b.unitnum 都为 null,是否有比较运算符使 a.unitnum = b.unitnum 为 true?似乎 a.unitnum IS b.unitnum 无效

最佳答案

是的,有 IS DISTINCT FROM and IS NOT DISTINCT FROM

postgres=# \pset null ****
Null display is "****".
postgres=# select null = null;
┌──────────┐
│ ?column? │
╞══════════╡
│ **** │
└──────────┘
(1 row)

postgres=# select null is not distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ t │
└──────────┘
(1 row)

postgres=# select 10 = null;
┌──────────┐
│ ?column? │
╞══════════╡
│ **** │
└──────────┘
(1 row)

postgres=# select 10 is distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ t │
└──────────┘
(1 row)

postgres=# select 10 is not distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ f │
└──────────┘
(1 row)

postgres=# select 10 is not distinct from 20;
┌──────────┐
│ ?column? │
╞══════════╡
│ f │
└──────────┘
(1 row)

关于postgresql - 比较两个可能为空的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43549915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com