Search code examples
sqlpostgresqlcountnull

How to count null values in postgresql?


select distinct "column" from table;

output:

    column
1     0.0
2     [null]
3     1.0

But when I try to count the null values

select count("column") from train where "column" is NULL;

Gives output 0 (zero)

Can you suggest where it's going wrong?


Solution

  • Use count(*):

    select count(*) from train where "column" is NULL;
    

    count() with any other argument counts the non-NULL values, so there are none if "column" is NULL.