在PostgreSQL中的任何列中查找具有NULL值的所有行

有很多类似的问题,但没有一个解决这个问题. The closest one I could findsql Server提供了一个答案,但我正在寻找一种在Postgresql中执行此操作的方法.

如何只选择任何列中具有NULL值的行?

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

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

但是不清楚如何检查NULL值的多个列名.显然这不行:

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

my Googling没有任何有用的东西.

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

the documentation

If the expression is row-valued,then IS NULL is true when the row
expression itself is null or when all the row’s fields are null,while
IS NOT NULL is true when the row expression itself is non-null and all
the row’s fields are non-null.

所以:

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)

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...