COUNT and GROUP BY performing strangely - Mailing list pgsql-novice

From James David Smith
Subject COUNT and GROUP BY performing strangely
Date
Msg-id CAMu32AASscD4h6wQW6xO1thpuWfYpq3e1ML04-zZNksHykXsFg@mail.gmail.com
Whole thread Raw
Responses Re: COUNT and GROUP BY performing strangely  (Jayadevan M <maymala.jayadevan@gmail.com>)
Re: COUNT and GROUP BY performing strangely  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-novice
Hi everyone,

Any thoughts on the below three queries please?

james_traffic=# SELECT  count(*) FROM stage;
 count
--------
 430991
(1 row)

james_traffic=# SELECT bad_flag, count(bad_flag) FROM stage GROUP BY bad_flag;
 bad_flag | count
----------+-------
           |     0
        1 |  4102
(2 rows)

james_traffic=# SELECT count(bad_flag) FROM stage;
 count
-------
  4102
(1 row)

 I'm confused as to why the second query doesn't return this:

 bad_flag  | count
--------------+-------
               | 426889
        1     |  4102

It should count the records surely, even if the field is blank/null ?

Thanks

James


pgsql-novice by date:

Previous
From: Luca Ferrari
Date:
Subject: Re: Using index name in select Query
Next
From: Jayadevan M
Date:
Subject: Re: COUNT and GROUP BY performing strangely