Re: [HACKERS] Re: [GENERAL] Re: [PHP3] Re: PostgreSQL vs Mysql comparison - Mailing list pgsql-hackers

The Hermit Hacker <scrappy@hub.org> writes:
> Anyone want to comment on this one?  Just tested with v6.5.0 and it still
> exists there...

> vhosts=> create table test ( a int, b char );
> CREATE
> vhosts=> insert into test values ( 1, 'a' );
> INSERT 149258 1
> vhosts=> select a from test group by a having a > 0;
> ERROR:  SELECT/HAVING requires aggregates to be valid

That's not a bug, it means what it says: HAVING clauses should contain
aggregate functions.  Otherwise they might as well be WHERE clauses.
(In this example, flushing rows with negative a before the group step,
rather than after, is obviously a win, not least because it would
allow the use of an index on a.)

However, I can't see anything in the SQL92 spec that requires you to
use HAVING intelligently, so maybe this error should be downgraded to
a notice?  "HAVING with no aggregates would be faster as a WHERE"
(but we'll do it anyway to satisfy pedants...)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Planner drops unreferenced tables --- bug, no?
Next
From: Oleg Bartunov
Date:
Subject: 6.5.2 vacuum NOTICE messages