有许多slightly similar个问题,但没有一个能准确地解决这个问题."Find All Rows With Null Value(s) in Any Column"是我能找到的最接近的一个,它为SQL Server提供了一个答案,但我正在寻找一种在PostgreSQL中实现这一点的方法.

如何仅 Select 在any列中有空值的行?

我可以很容易地得到所有的列名:

select column_name from information_schema.columns where table_name = 'A';

但目前尚不清楚如何判断多个列名中的空值.显然这行不通:

select* from A where (
  select column_name from information_schema.columns where table_name = 'A';
) IS NULL;

searching没有发现任何有用的东西.

推荐答案

你可以用NOT(<table> IS NOT NULL).

the documentation开始:

如果表达式是行值表达式,则当该行

所以:

SELECT * FROM t;
┌────────┬────────┐
│   f1   │   f2   │
├────────┼────────┤
│ (null) │      1 │
│      2 │ (null) │
│ (null) │ (null) │
│      3 │      4 │
└────────┴────────┘
(4 rows)

SELECT * FROM t WHERE NOT (t IS NOT NULL);
┌────────┬────────┐
│   f1   │   f2   │
├────────┼────────┤
│ (null) │      1 │
│      2 │ (null) │
│ (null) │ (null) │
└────────┴────────┘
(3 rows)

Postgresql相关问答推荐

Redis作为postgreSQL嵌套数据的缓存

"错误:无法创建用户:错误:关系\users\违反了非空约束

连接到 PostgreSQL 时没有属性执行错误

在 jOOQ 中 Select 相同的命名列

PostgreSQL - 如何获得前一个月和一周的价值?

如何为基于复合类型的 Postgres DOMAIN 定义 CHECK 约束

如何展平也在关系中使用的区分大小写的列

查找最小值和最大值

如何在 postgresql 中创建一个空的 JSON 对象?

Django + Postgres + 大时间序列

如何使用 SpringBoot + JPA 存储 PostgreSQL jsonb?

PostgreSQL 可以对数组元素有唯一性约束吗?

timezone date_trunc 函数

在 PostgreSQL 中表示Sparse稀疏数据

在 Windows 10 中执行时,Docker 容器关闭并给出data directory has wrong ownership错误

使用枚举与布尔值?

在 Postgres 中显示关系、序列和函数的默认访问权限

Windows 上的 GeoDjango:Could not find the GDAL library" / "OSError: [WinError 126] The specified module could not be found

postgresql中的移动平均线

JOIN (SELECT ... ) ue ON 1=1?