Re: group by - Mailing list pgsql-novice

From Tom Lane
Subject Re: group by
Date
Msg-id 26434.1011125032@sss.pgh.pa.us
Whole thread Raw
In response to group by  (Ewald Geschwinde <webmaster@geschwinde.net>)
List pgsql-novice
Ewald Geschwinde <webmaster@geschwinde.net> writes:
> I have a problem whith group by and aliases

> select s1.channelname as channelname, s1.id as channelid,
> count(*) as anz from mgw_news n left join mgw_news_channels s1 on
> n.channelid = s1.id group by channelid, channelname order by channelid,
> channelname

I would expect "group by channelid" to refer to n.channelid, which is
the SQL-mandated interpretation.  Using aliases in GROUP BY is a flat
violation of the SQL92 standard, but a lot of implementations accept it
anyway.  However, when there is an ambiguous situation, as here, we must
treat GROUP BY as referring to the underlying column name not the alias,
else we do not conform to the standard.

> this runs under mysql and postgresql seems not to accept aliases in
> group by

> cause when i'm changing channelid to s1.id it works perfectly

> is anyone working on that?

No, because it's not a bug.  MySQL's behavior is not SQL92 compliant,
if you've described it accurately.

            regards, tom lane

pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: group by
Next
From: Burra
Date:
Subject: PL/PGSQL