From: | Chris Campbell <chris(at)bignerdranch(dot)com> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | pgsql-hackers(at)postgresql(dot)org, Mark Woodward <pgsql(at)mohawksoft(dot)com> |
Subject: | Re: Syntax bug? Group by? |
Date: | 2006-10-17 20:00:26 |
Message-ID: | 9FE561EF-FDAE-4338-A608-2DBD7D03F9CF@bignerdranch.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.
Thanks!
- Chris
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Sunday | 2006-10-17 20:26:44 | Re: Syntax bug? Group by? |
Previous Message | Peter Eisentraut | 2006-10-17 19:19:17 | Re: Syntax bug? Group by? |