gpt4 book ai didi

SQL: "condition is not true"模式替代 "is null or not (condition)"

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

在 SQL 中(特别是 Postgres):

子句 where not foo='bar' in case foo is null 评估为某种 null,导致该行不是包含在结果中。

另一方面,子句 where (foo='bar') is not true where foo is null 评估为 true (该行包含在结果中)。

那么使用 (foo='bar') is not true 是否等同于 foo is null or not foo='bar'

似乎人们出于某种原因并没有使用这种模式,我是不是漏掉了什么?

最佳答案

So is the use of (foo='bar') is not true equivalent to foo is null or not foo='bar'?

是的。或者更简单:

foo IS NULL OR foo <> 'bar'

或者更简单:

foo IS DISTINCT FROM 'bar'

使用后者。
手册章节中的详细信息 Comparison Functions and Operators.
相关:

关于SQL: "condition is not true"模式替代 "is null or not (condition)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57206821/

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