Re: Aliased SubSelect in HAVING clause bug -- in progress? - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Aliased SubSelect in HAVING clause bug -- in progress?
Date
Msg-id 24750.1047449620@sss.pgh.pa.us
Whole thread Raw
In response to Aliased SubSelect in HAVING clause bug -- in progress?  (Josh Berkus <josh@agliodbs.com>)
Responses Re: Aliased SubSelect in HAVING clause bug -- in progress?
List pgsql-bugs
Josh Berkus <josh@agliodbs.com> writes:
> SELECT a.id, b.type, max(b.number),
>       (SELECT count(*) from c where c.b_type = b.type) as count_c
> FROM a, b
> WHERE a.id = b.a_id
> GROUP BY a.id, b.type
> HAVING count_c > 2;
> Will get a:
> ERROR: Attribute "count_c" not found.

As it should.

> I'd guess that this is being worked on for 7.4/8.0?

No, because it's not a bug.  The SELECT list is evaluated after HAVING,
so what you are asking for is an impossibility in the SQL semantic
model.

(Yeah, I know there's some laxity in GROUP BY ... one of our worse
mistakes IMHO ...)

            regards, tom lane

pgsql-bugs by date:

Previous
From: Josh Berkus
Date:
Subject: Aliased SubSelect in HAVING clause bug -- in progress?
Next
From: "cn cn"
Date:
Subject: RI Bug In Inherited Table