Re: GROUP BY column alias? - Mailing list pgsql-general

From Scott Bailey
Subject Re: GROUP BY column alias?
Date
Msg-id 4B7DC4BE.6010409@comcast.net
Whole thread Raw
In response to Re: GROUP BY column alias?  ("Eric B. Ridge" <ebr@tcdi.com>)
Responses Re: GROUP BY column alias?  ("Eric B. Ridge" <ebr@tcdi.com>)
List pgsql-general
Eric B. Ridge wrote:
> On Feb 18, 2010, at 4:31 PM, Scott Bailey wrote:
>> I'm not sure why you would be surprised by that behavior. You are grouping by a timestamp, so any microsecond
differencewill be a new group. 
>
> I get that. ;)  Hence the ::date.  This is what doesn't make sense:
>
> Expected:     select day::date as bar, count(*) from foo group by bar;
> Not Expected: select day::date as day, count(*) from foo group by day;
>
> If I alias it to something other than the actual column name, it does what I expect.  But if I alias it to the column
name,it doesn't. 
>
> I would have thought that the precedence rules would resolve the alias first, then the column name, but that doesn't
seemto be the case. 

SQL name resolution rules are that column names have higher precedence
than aliases and variables. So it will always bind to the column not the
alias.

Scott

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Persistent identifiers for Postgres users
Next
From: "Eric B. Ridge"
Date:
Subject: Re: GROUP BY column alias?