count distinct and group by - Mailing list pgsql-general

From Szymon Guz
Subject count distinct and group by
Date
Msg-id CAFjNrYtrTMFmRVrz=PyWkm-SBQQq28DvTzmsaYuVP-bqjPERDQ@mail.gmail.com
Whole thread Raw
Responses Re: count distinct and group by  (Magnus Hagander <magnus@hagander.net>)
Re: count distinct and group by  (Geoff Winkless <pgsqladmin@geoff.dj>)
Re: count distinct and group by  (Andomar <andomar@aule.net>)
List pgsql-general
Hi,
I'm not sure why there is a reason for such behaviour.

For this table:

create table bg(id serial primary key, t text);

This works:

select count(id) from bg;

This works:

select count(distinct id) from bg;

And this doesn't:

select count(distinct id) from bg order by id;
ERROR:  column "bg.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select count(distinct id) from bg order by id;

thanks,
Szymon

pgsql-general by date:

Previous
From: Tim Clarke
Date:
Subject: Re: detached query?
Next
From: Magnus Hagander
Date:
Subject: Re: count distinct and group by