Re: GROUP BY column alias?

From: Scott Bailey <artacus(at)comcast(dot)net>
To: "Eric B(dot) Ridge" <ebr(at)tcdi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: GROUP BY column alias?
Date: 2010-02-18 22:52:46
Message-ID: 4B7DC4BE.6010409@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 difference will 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 seem to 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric B. Ridge 2010-02-18 23:17:04 Re: GROUP BY column alias?
Previous Message Alvaro Herrera 2010-02-18 22:22:33 Re: Persistent identifiers for Postgres users