Re: HAVING clause working in postgres 8.0, but not in 8.2

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ujkavlade(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: HAVING clause working in postgres 8.0, but not in 8.2
Date: 2007-07-03 22:13:13
Message-ID: 13975.1183500793@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ujkavlade(at)gmail(dot)com writes:
> In PostgreSql 8.0, SELECT number FROM numbers HAVING number = 5;
> returns 5

> But in 8.2, it gives me the following error: ERROR: column
> "numbers.number" must appear in the GROUP BY clause or be used in an
> aggregate function.

> In the documentation, it says that HAVING can be used without GROUP BY
> or aggregate functions.

It can; whether it's useful or not is another question.

Per the 8.1 release notes:

* Fix HAVING without any aggregate functions or GROUP BY so that the
query returns a single group

Previously, such a case would treat the HAVING clause the same as
a WHERE clause. This was not per spec.

The above query is incorrect because it hasn't done anything to create
a grouped column.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2007-07-03 22:37:57 Mugs 'n stuff
Previous Message Ron Johnson 2007-07-03 21:46:05 Re: What O/S or hardware feature would be useful for databases?