From: | Dan Langille <dan(at)langille(dot)org> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | 7.3 GROUP BY differs from 7.2 |
Date: | 2003-02-22 01:18:02 |
Message-ID: | 20030221193223.G76894@xeon.unixathome.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-sql |
I notice this today when migrating an application from 7.2 to 7.3. The
column name is not being recognized.
See also: http://archives.postgresql.org/pgsql-sql/2003-02/msg00480.php
This is the query in question:
SELECT element_id as wle_element_id, COUNT(watch_list_id)
FROM watch_list JOIN watch_list_element
ON watch_list.id = watch_list_element.watch_list_id
WHERE watch_list.user_id = 1
GROUP BY watch_list_element.element_id;
ERROR: Attribute unnamed_join.element_id must be GROUPed or used in an
aggregate function
Of note is the column watch_list_element.element_id. The following
variation works:
SELECT element_id as wle_element_id, COUNT(watch_list_id)
FROM watch_list JOIN watch_list_element
ON watch_list.id = watch_list_element.watch_list_id
WHERE watch_list.user_id = 1
GROUP BY element_id;
i.e. remove the table name from the GROUP BY field. Similar success is
obtained if you add the table name to element_id in both the SELECT and
the GROUP BY.
Similarly, this works:
SELECT element_id as wle_element_id, COUNT(watch_list_id)
FROM watch_list JOIN watch_list_element
ON watch_list.id = watch_list_element.watch_list_id
WHERE watch_list.user_id = 1
GROUP BY wle_element_id;
i.e. use the column alias.
Under 7.2.3, all of the above queries work.
cheers
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-02-22 03:28:56 | Re: 7.3 GROUP BY differs from 7.2 |
Previous Message | pgsql-bugs | 2003-02-21 21:42:36 | Bug #900: Win32 Postgres ODBC driver does not allow 2 connections to a database at the same time |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2003-02-22 02:09:49 | Re: 7.3 "group by" issue |
Previous Message | Dan Langille | 2003-02-22 00:13:28 | Re: 7.3 "group by" issue |