| From: | Jayadevan M <maymala(dot)jayadevan(at)gmail(dot)com> |
|---|---|
| To: | James David Smith <james(dot)david(dot)smith(at)gmail(dot)com> |
| Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: COUNT and GROUP BY performing strangely |
| Date: | 2013-10-25 11:22:19 |
| Message-ID: | CAFS1N4iviBdOuTrC2ad=V6N+WVO=fOYrPFsiLrhL0bkNd8C+og@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
http://stackoverflow.com/questions/2054235/why-doesnt-postgres-group-by-null-select-counts
http://www.postgresql.org/docs/9.0/static/functions-aggregate.html
says "number of input rows for which the value ofexpression is not null"
On Fri, Oct 25, 2013 at 3:38 PM, James David Smith <
james(dot)david(dot)smith(at)gmail(dot)com> wrote:
> 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
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | James David Smith | 2013-10-25 11:24:44 | Re: COUNT and GROUP BY performing strangely |
| Previous Message | Thomas Kellerer | 2013-10-25 10:26:41 | Re: COUNT and GROUP BY performing strangely |