
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, Pennsylvania 19026

Mon, 10 May 1999 01:03:22 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] Parser bug: alias is a "non-group column"?
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
but
	SELECT 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, value
	HAVING 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) but
	SELECT name AS tempname, value FROM t1 GROUP BY tempname, value
	HAVING value/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

Mon, 10 May 1999 12:38:51 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [HACKERS] Parser bug: alias is a "non-group column"? 