aliases, &c in HAVING clause? - Mailing list pgsql-hackers

From david@fetter.org (David Fetter)
Subject aliases, &c in HAVING clause?
Date
Msg-id NmGdnTtETvgXyqfd3czS-w@speakeasy.net
Whole thread Raw
Responses Re: aliases, &c in HAVING clause?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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 david@fetter.org 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


pgsql-hackers by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Heads up: 7.3.6 and 7.4.2 coming soon
Next
From: "Thomas Hallgren"
Date:
Subject: Re: Pl/Java - next step?