X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E80AD475AEC for ; Fri, 21 Feb 2003 20:23:30 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 19149-07 for ; Fri, 21 Feb 2003 20:23:02 -0500 (EST) Received: from xeon.unixathome.org (bast.unixathome.org [66.11.174.150]) by postgresql.org (Postfix) with ESMTP id B4396474E4F for ; Fri, 21 Feb 2003 20:14:18 -0500 (EST) Received: by xeon.unixathome.org (Postfix, from userid 1000) id 036D33F4A; Fri, 21 Feb 2003 20:18:03 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by xeon.unixathome.org (Postfix) with ESMTP id F08FD3F49 for ; Fri, 21 Feb 2003 20:18:02 -0500 (EST) Date: Fri, 21 Feb 2003 20:18:02 -0500 (EST) From: Dan Langille X-X-Sender: dan@xeon.unixathome.org To: pgsql-bugs@postgresql.org Subject: 7.3 GROUP BY differs from 7.2 Message-ID: <20030221193223.G76894@xeon.unixathome.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/105 X-Sequence-Number: 5521 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