Thread: Re: [HACKERS] Parser bug: alias is a "non-group column"?

Re: [HACKERS] Parser bug: alias is a "non-group column"?

From
Bruce Momjian
Date:
Where did we leave this?


> Given
>     create table t1 (name text, value float8);
> 
> this works:
>     SELECT name, value FROM t1 GROUP BY name, value
>     HAVING value/AVG(value) > 0.75;
> 
> but this doesn't:
>     SELECT name AS tempname, value FROM t1 GROUP BY name, value
>     HAVING value/AVG(value) > 0.75;
>     ERROR:  Illegal use of aggregates or non-group column in target list
> 
> Curiously, it's fine if the HAVING clause is omitted ... since name is
> not mentioned in the HAVING clause, I don't see the connection ...
> 
> 6.4.2 and current sources show the same behavior.
> 
>             regards, tom lane
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] Parser bug: alias is a "non-group column"?

From
Tom Lane
Date:
Bruce Momjian <maillist@candle.pha.pa.us> writes:
> Where did we leave this?

It's still broken.  I have the following notes in my todo list:

Inconsistent handling of attribute renaming:create table t1 (name text, value float8);select name as n1 from t1  where
n1 = 'one' ;ERROR:  attribute 'n1' not found
 
butSELECT name AS tempname, value FROM t1 GROUP BY name, value ;SELECT name AS tempname, value FROM t1 GROUP BY
tempname,value ;
 
both work.  Even stranger,SELECT name AS tempname, value FROM t1 GROUP BY name, valueHAVING value/AVG(value) >
0.75;ERROR: Illegal use of aggregates or non-group column in target list
 
(it thinks tempname is not in the GROUP BY list) butSELECT name AS tempname, value FROM t1 GROUP BY tempname,
valueHAVINGvalue/AVG(value) > 0.75;
 
works!  (6.4.2 has same behavior for all cases...)


Looks like the parser has some problems in the presence of column
renaming.  Since 6.4.2 has the same bug I doubt this qualifies as a
showstopper for 6.5; I have other todo items that I consider higher
priority.  If someone else wants to dig into this, be my guest...
        regards, tom lane