微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在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)

原文地址:https://www.jb51.cc/postgresql/192195.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐