Re: Do I just not understand count()?

From: Ben <bench(at)silentmedia(dot)com>
To: Gregory Wood <gregw(at)com-stock(dot)com>
Cc: PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Do I just not understand count()?
Date: 2002-04-08 18:45:28
Message-ID: Pine.LNX.4.30.0204081142010.9115-100000@gilgamesh.eos.SilentMedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

That's what I'd normally do to, but in this case I want to run a query
more like

select count(a=1), count(a=2) from t

and I don't want to do multiple selects, because I'm selecting other stuff
too, which takes time, and I figure as long as postgres is looking at
those rows, it might as well tally up the counts of a=1 and a=2.

On Mon, 8 Apr 2002, Gregory Wood wrote:

> I don't think I've seen that particular syntax used before (I would say
> select count(a) from t where a=1;), but since the query appears to work, I
> won't argue.
>
> Why do you think it should give you a result of 1? There are two rows
> containing a value of 1 for a, hence it returns 2.
>
> Greg
>
> ----- Original Message -----
> From: "Ben" <bench(at)silentmedia(dot)com>
> To: <pgsql-general(at)postgresql(dot)org>
> Sent: Monday, April 08, 2002 2:25 PM
> Subject: [GENERAL] Do I just not understand count()?
>
>
> > If I have the table t defined as:
> >
> > a
> > ---
> > 1
> > 1
> > 2
> >
> >
> > and I say:
> >
> > select count(a=1) from t;
> >
> > should it give me 1 or 2 as a result? I'm getting 2, and I'd think I
> > should get 1....
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Esposito 2002-04-08 18:56:38 Re: vacuuming not working?
Previous Message Jeffrey W. Baker 2002-04-08 18:45:01 Re: vacuuming not working?