加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 16:19:21 所属栏目:百科 来源:网络整理
导读:有很多类似的问题,但没有一个解决这个问题. The closest one I could find为SQL Server提供了一个答案,但我正在寻找一种在PostgreSQL中执行此操作的方法. 如何只选择任何列中具有NULL值的行? 我可以很容易地得到所有的列名称: select column_name from inf
有很多类似的问题,但没有一个解决这个问题. The closest one I could find为SQL 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读