Re: [BUGS] We are not following the spec for HAVING without GROUP

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [BUGS] We are not following the spec for HAVING without GROUP
Date: 2005-03-14 04:24:18
Message-ID: 87mzt67t3h.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

> On Wed, 2005-03-09 at 21:21 -0500, Tom Lane wrote:
> > Comments? Can anyone confirm whether DB2 or other databases allow
> > ungrouped column references with HAVING?

Mysql treats ungrouped columns as an assertion that those columns will all be
equal for the group and it can pick an arbitrary one. Essentially it does an
implicit "first(x) AS x". The expected use case is for things like:

select count(*),a.*
from a,b
where a.pk = b.a_fk
group by a.pk

I've noticed quite frequently scenarios where this idiom would be very handy.
I usually either end up rewriting the query to have nested subqueries so I can
push the grouping into the subquery. This doesn't always work though and
sometimes I end up listing several, sometimes dozens, of columns like
"first(x) AS x" or else end up

--
greg

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruno Wolff III 2005-03-14 04:56:55 Re: [BUGS] We are not following the spec for HAVING without GROUP
Previous Message Neil Conway 2005-03-14 03:00:41 Re: BUG #1540: Enhancement request: 'ambiguous' column reference

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruno Wolff III 2005-03-14 04:56:55 Re: [BUGS] We are not following the spec for HAVING without GROUP
Previous Message Bruce Momjian 2005-03-14 03:00:37 Re: TODO item: support triggers on columns