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

From Eric B. Ridge
Subject Re: GROUP BY column alias?
Date
Msg-id 242B5FAC-7C65-4A95-81F8-C990D3C432AB@tcdi.com
Whole thread Raw
In response to Re: GROUP BY column alias?  (Scott Bailey <artacus@comcast.net>)
Responses Re: GROUP BY column alias?
List pgsql-general
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. 

> If you want to make that work try:
> SELECT day::date, --no need to alias as same name

The "no need to alias as same name" isn't true in my case because the queries I'm dealing with are machine generated,
andthat's what the generator does, in all cases. 

eric

pgsql-general by date:

Previous
From: Reid Thompson
Date:
Subject: Re: SQL select return into PSQL variables.
Next
From: Alvaro Herrera
Date:
Subject: Re: Persistent identifiers for Postgres users