Unix Technical Forum

HAVING clause working in postgres 8.0, but not in 8.2

This is a discussion on HAVING clause working in postgres 8.0, but not in 8.2 within the Pgsql General forums, part of the PostgreSQL category; --> Hello all, We have recently upgrade our postgres server from 8.0 to 8.2. I am experiencing some difficulties in ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 06:12 PM
ujkavlade@gmail.com
 
Posts: n/a
Default HAVING clause working in postgres 8.0, but not in 8.2

Hello all,

We have recently upgrade our postgres server from 8.0 to 8.2. I am
experiencing some difficulties in SQL queries.
Let's say I have a table NUMBERS (number (integer)) which has values
1, 5 and 8.

SELECT number FROM numbers; will return 1, 5 and 8.

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.

Has anybody already experienced this, is this a bug or am I missing
something?

TIA,
Vladimir

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 06:14 PM
Tom Lane
 
Posts: n/a
Default Re: HAVING clause working in postgres 8.0, but not in 8.2

ujkavlade@gmail.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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com