RE: [HACKERS] SELECT ... AS ... names in WHERE/GROUP BY/HAVING
От
Ansley, Michael
Тема
RE: [HACKERS] SELECT ... AS ... names in WHERE/GROUP BY/HAVING
Дата
Msg-id
1BF7C7482189D211B03F00805F8527F748C359@S-NATH-EXCH2
Список
Hi, Tom,
It's my understanding that WHERE and GROUP BY will only accept table or view
columns, while ORDER BY and HAVING will accept SELECT columns (aliases) as
well. I'll double check this with Oracle (Oracle tends to be pretty SQL
compliant), but it makes sense to me.
So according to my view of the world ;-) HAVING is broken, because it
rejects aliases, and GROUP BY is broken because it accepts them. Of course,
I haven't looked at the spec, and Oracle could adhere to an older spec which
may have changed. At least I don't have to take any responsibility for my
claims ;-)
OK, I've just checked it against Oracle, and what you had originally seems
to be the way to go: no aliases for WHERE, GROUP BY, or HAVING. However,
aggregates are allowed in the HAVING clause. Also, aliases are allowed for
ORDER BY.
So, according to Oracle's view of the world, HAVING is orrect because it
rejects aliases, but GROUP BY is broken because it accepts them.
MikeA
-----Original Message-----
From: Tom Lane
To: pgsql-hackers@postgreSQL.org
Sent: 99/12/15 07:05
Subject: [HACKERS] SELECT ... AS ... names in WHERE/GROUP BY/HAVING
Who's up for a little language-lawyering discussion?
I have just noticed that our parser is probably in error in treating
GROUP BY and ORDER BY expressions similarly. This came up while
checking whether we were doing the right thing in rejecting
SELECT complicated-expression AS foo FROM table WHERE foo < 42;
Our parser will accept AS-names in ORDER BY and GROUP BY clauses,
but not in WHERE or HAVING. But eyeballing the spec makes it look like
AS-names should *only* be recognized in ORDER BY, nowhere else. The
spec's organization of a SELECT query is
::= [ ]
::= SELECT [ ] В списке pgsql-hackers по дате отправления
От: Tom Lane
Дата: