Re: Do I just not understand count()?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gregory Wood" <gregw(at)com-stock(dot)com>
Cc: "Ben" <bench(at)silentmedia(dot)com>, "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Do I just not understand count()?
Date: 2002-04-08 19:30:41
Message-ID: 22875.1018294241@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Gregory Wood" <gregw(at)com-stock(dot)com> writes:
> I'm not sure exactly what it does with "a=1" though... I'm
> guessing that it returns a boolean value, which means that it counts as a
> row (only NULL values are not counted in count()).

Yup, Greg gets a gold star: COUNT *only* cares whether its input is NULL
or not, not what specific value it might have. This is per SQL spec.

The nearby suggestions involving SUM() look like they would work to
accumulate counts of different conditions in a single pass.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message S Dawalt 2002-04-08 19:35:35 Re: PHP, HTML Forms & PostgreSQL
Previous Message Michael Adler 2002-04-08 19:10:25 Re: inherited columns as foreign keys WAS "no subject"