Re: [BUGS] We are not following the spec for HAVING without GROUP - Mailing list pgsql-hackers

From Greg Stark
Subject Re: [BUGS] We are not following the spec for HAVING without GROUP
Date
Msg-id 87mzt67t3h.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: [BUGS] We are not following the spec for HAVING without GROUP  (Mark Shewmaker <mark@primefactor.com>)
Responses Re: [BUGS] We are not following the spec for HAVING without GROUP
Re: [BUGS] We are not following the spec for HAVING without GROUP
List 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,bwhere a.pk = b.a_fkgroup 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



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: TODO item: support triggers on columns
Next
From: Bruno Wolff III
Date:
Subject: Re: [BUGS] We are not following the spec for HAVING without GROUP