postgresql - 如何检查一行中的空值?
问题描述
我想要其中至少有一列具有空值的行。我尝试使用如下行表达式:
SELECT *
FROM <table>
WHERE <table> IS NULL
但它不起作用。我的查询不正确还是?
PS我使用的是13.4版
解决方案
您可以在 WHERE 子句中引用表别名。该条件where the_table is not null
将返回所有列都不为空的行。
相反的(至少一列为空)可以通过否定表达式来实现:
select *
from the_table
where not (the_table is not null);
看起来有点奇怪,但它与the_table is null
- 不一样,因为对表(别名)的引用指的是现有行。如果存在一行,则“整行”不能为空。
这个:
with the_table (col1, col2, col3) as (
values
(1,null,null),
(null,2,null),
(null,3,4),
(5,6,7)
)
select *
from the_table
where not (the_table is not null);
返回:
col1 | col2 | col3
-----+------+-----
1 | |
| 2 |
| 3 | 4
推荐阅读
- webpack - webpack 4.8.3 e.merge 不是函数异常
- c# - 实体框架 6 -> 具有多个键的通用 DbSet.Find 方法
- string - 使用 Bash 替换字符串并将部分移动到结果
- java - 在 lambda 中使用集合时,PMD LocalVariableCouldBeFinal 仍然是有效规则吗?
- java - 使用 Spring Boot 和 AngularJS 以国际数字格式存储和处理数字
- css - Base64 背景图像被解析为服务器中的相对路径
- node.js - 如何在nodejs中访问app.use方法中的变量?
- javascript - 如何在 Winston 中实现“isDebugEnabled”防护?
- typescript - 离子 - Firebase 身份验证错误
- angular - PrimeNG 树扩展