postgresql - Postgres 有必要在这个 where 子句中包含两个谓词吗?
问题描述
我想编写一个查询,它返回所有action1
不是的行't'
(包括实例 where action1
is null
)
此查询不返回null
记录:
select *
from actions
where action1 <> 't'
这个查询确实返回了null
记录,但我很惊讶这两个谓词都是必要的
select *
from event_actions
where action_c2 is null or action_c2 <> 't'
有没有办法在没有两个谓词的情况下编写这个查询?
解决方案
您可以IS DISTINCT FROM
在比较中使用该构造,它将其视为null
不同于任何非空值的已知值,即
select *
from actions
where action1 is distinct from 't'
a is distinct from b
相当于
case
when a is null then b is null
else a is not null then b is not null and a = b
end
推荐阅读
- python - Pandas:新列中与前行差异的最大值列表
- ios - 自我调整 UICollectionView `reloadItems(at: IndexSet)` 将在其他部分单元格上调用 `cellForItemAt`
- dart - 为什么属性需要 Dart 中非语法糖初始值设定项的默认值?
- javascript - 不同的javascript方法中的不同正则表达式行为
- flutter - Flame 如何支持 Rive 动画?
- html - 为美国观众使用适当的语言子标签
- php - 如何通过改变捐赠总额来减少现金分配总额
- jenkins-plugins - jenkins 自定义插件 java 代码从从机读取文件
- r - R 如何获取美国市场的最后交易日?
- c# - 如何修复 Assets\Scripts\PlayerController.cs(48,9):错误 CS0103:当前上下文中不存在名称“CheckIfWallSliding”?