How to find all rows with a NULL value in any column using PostgreSQL

前端 未结 1 1084
陌清茗
陌清茗 2020-12-08 19:49

There are many slightly similar questions, but none solve precisely this problem. \"Find All Rows With Null Value(s) in Any Column\" is the closest one I could fin

相关标签:
1条回答
  • 2020-12-08 20:35

    You can use NOT(<table> IS NOT NULL).

    From 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.

    So :

    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)
    
    0 讨论(0)
提交回复
热议问题