From: Dan Langille <dan@langille.org>
To: pgsql-bugs@postgresql.org
Subject: 7.3 GROUP BY differs from 7.2
Date: Fri, 21 Feb 2003 20:18:02 -0500 (EST)
Message-ID: <20030221193223.G76894@xeon.unixathome.org> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dan@langille.org, pgsql-bugs@postgresql.org
Subject: Re: 7.3 GROUP BY differs from 7.2
In-Reply-To: <20030221193223.G76894@xeon.unixathome.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox