Re: We are not following the spec for HAVING without GROUP BY

Greg Stark <gsstark@mit.edu>

From: Greg Stark <gsstark@mit.edu>
To: pgsql-hackers@postgresql.org
Date: 2005-03-10T03:46:26Z
Lists: pgsql-bugs, pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> In particular this whole business of "moving HAVING into WHERE" is
> wrong and should go away.

It sort of seems like "select aggregate(col) from tab" with no GROUP BY clause
is a bit of a special case. The consistent thing to do would be to return no
records. It's only due to the special case that SQL returns a single record
for this case.

It seems like this special case is the only way to expose this difference
between a WHERE clause and a HAVING clause with an aggregate-free expression.

It seems like all that's needed is a simple flag on the Aggregate node that
says whether to output a single record if there are no input records or to
output no records.

-- 
greg