Re: sql query bug???

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Ribe <scott_ribe(at)elevated-dev(dot)com>
Cc: Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: sql query bug???
Date: 2012-02-06 05:46:50
Message-ID: 28445.1328507210@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scott Ribe <scott_ribe(at)elevated-dev(dot)com> writes:
> Is this a bug (in 9.0.4), or have I just gone cross-eyed from too much work?
> The query:

> select t0."ICD9", t0."Description", count(*)
> from (select distinct "Person_Id", "ICD9", "Description" from "PatientDiagnoses") as t0
> group by (t0."ICD9", t0."Description")
> order by count(*) desc limit 10;

> The error:

> column "t0.ICD9" must appear in the GROUP BY clause or be used in an aggregate function

Drop the parentheses in the GROUP BY. As is, this is requesting to
group by the composite value ROW(t0."ICD9", t0."Description").
You could argue that that's sufficient to determine both of those column
values, but PG doesn't make that deduction (and, I think, is not
required to by spec).

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-02-06 05:48:46 Re: SPI functions to work with the Execution Plan
Previous Message dhaval jaiswal 2012-02-06 05:20:39 Re: Error while importing CSV file