
Is this a known problem? Is there a work-around?

create table t (c char, i int);
insert into t values ('a', 1);
insert into t values ('a', 1);
insert into t values ('a', 2);
insert into t values ('b', 2);

select distinct on (c, i) c, count(i) from t group by c;
ERROR:  Attribute t.i must be GROUPed or used in an aggregate function

-- 

Mark Hollomon
mhh@nortelnetworks.com
ESN 451-9008 (302)454-9008

Mon, 07 Aug 2000 11:07:03 -0400
"Mark Hollomon" <mhh@nortelnetworks.com>
'GROUP BY' / 'DISTINCT' interaction bug?
"Mark Hollomon" <mhh@nortelnetworks.com> writes:
> select distinct on (c, i) c, count(i) from t group by c;
> ERROR:  Attribute t.i must be GROUPed or used in an aggregate function

Why do you think that's a bug?  The DISTINCT clause requires use of
the ungrouped value of i, doesn't it?

			regards, tom lane

Mon, 07 Aug 2000 11:59:38 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: 'GROUP BY' / 'DISTINCT' interaction bug? 