Kind people, I bumped across this several times, and am wondering what SQL99 and SQL200x have to say about column numbers or aliases in HAVING. SQL92 is fairly clear (no) but also somewhat out of date.
Here's a scenario: SELECT foo_name, count(*) as foo_count FROM foo GROUP BY foo_name HAVING foo_count > 2 ORDER BY foo_count DESC, foo_name; Another: SELECT foo_name, count(*) as foo_count FROM foo GROUP BY foo_name HAVING 2 > 2 -- OK, so this is a little weird, but it makes sense in context. ORDER BY 2 DESC, 1; I know pg throws some kind of parse error when I ask for that sort of thing, and that replacing the alias/number with its referent clears this up, but what do later standards have to say about doing or not doing the above? If they're ambiguous, are there good reasons why the above shouldn't work? TIA for any pointers on this :) Cheers, D -- David Fetter [EMAIL PROTECTED] http://fetter.org/ phone: +1 510 893 6100 mobile: +1 415 235 3778 Transported to a surreal landscape, a young girl kills the first woman she meets and then teams up with three complete strangers to kill again. Marin County newspaper's TV listing for The Wizard of Oz ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match