Re: Syntax bug? Group by?

From: "Mark Woodward" <pgsql(at)mohawksoft(dot)com>
To: "Chris Campbell" <chris(at)bignerdranch(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Syntax bug? Group by?
Date: 2006-10-17 20:47:23
Message-ID: 18220.24.91.171.78.1161118043.squirrel@mail.mohawksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 17, 2006, at 15:19, Peter Eisentraut wrote:
>
>> Mark Woodward wrote:
>>> Shouldn't this work?
>>>
>>> select ycis_id, min(tindex), avg(tindex) from y where ycis_id = 15;
>>>
>>> ERROR: column "y.ycis_id" must appear in the GROUP BY clause or be
>>> used in an aggregate function
>>
>> This would require a great deal of special-casing, in particular
>> knowledge of the = operator, and then the restriction to a particular
>> form of the WHERE clause. For overall consistency, I don't think this
>> should be allowed.
>
> In this particular case, the client constructing the query *knows*
> the value of ycis_id (since the client is generating the "ycis_id =
> 15" clause). It's technically just a waste of bandwidth and server
> resources to recalculate it. If you really want to replicate the
> output of the query you proposed, you could rewrite it on the client as:
>
> select 15 as ycis_id, min(tindex), avg(tindex) from y where
> ycis_id = 15;
>
> You could argue that the server should do this for you, but it seems
> ugly to do in the general case. And, like Peter points out, would
> need a lot of special-casing. I guess the parser could do it for
> expressions in the SELECT clause that exactly match expressions in
> the WHERE clause.
>

But, and here's the rub, which is the "correct" way to handle it? I'm
looking through the SQL99 spec to see if I can find an answer.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message George Pavlov 2006-10-17 20:55:21 Re: query log corrupted-looking entries
Previous Message Mark Woodward 2006-10-17 20:45:49 Re: Syntax bug? Group by?