Query GROUP BY - Mailing list pgsql-general

From Oleg Lebedev
Subject Query GROUP BY
Date
Msg-id 993DBE5B4D02194382EC8DF8554A527303354D@postoffice.waterford.org
Whole thread Raw
List pgsql-general
I have two similar queries. The first one uses an alias in the GROUP BY clause, which causes an error. The second query uses the actual column name in the GROUP BY clause and passes.
Note that the other GROUP BY parameter is an alias in both cases. So, why would GROUPing work for one alias, but not for the other?
 
Q1 (Fails):
SELECT     c.objectid AS charid,
                c.charname AS charname,
                SUM (num)
                FROM speccharacter c
                LEFT OUTER JOIN media m
                    ON     m.mediachar = c.objectid
                    AND    m.mediatype = '2'
GROUP BY charid, charname
ORDER BY charname
 
Q2 (Runs):
SELECT c.objectid AS charid,
                c.charname AS charname,
                SUM (num)
FROM speccharacter c
                LEFT OUTER JOIN media m
                    ON     m.mediachar = c.objectid
                    AND    m.mediatype = '2'
GROUP BY charid, c.charname
ORDER BY charname
 
 
 

*************************************

This email may contain privileged or confidential material intended for the named recipient only.
If you are not the named recipient, delete this message and all attachments.
Any review, copying, printing, disclosure or other use is prohibited.
We reserve the right to monitor email sent through our network.

*************************************

pgsql-general by date:

Previous
From: merlyn@stonehenge.com (Randal L. Schwartz)
Date:
Subject: Open Source Development Lab resources
Next
From: Christoph Dalitz
Date:
Subject: Re: Running PostgreSQL on Windows