Tom Lane wrote:
In this particular case you could say
... GROUP BY 1 ORDER BY 1;
"ORDER BY n" as a reference to the n'th SELECT output column is in the
SQL92 spec. (IIRC they removed it in SQL99, but we still support it,
and I think most other DBMSes do too.) "GROUP BY n" is *not* in any
version of the spec but we allow it anyway. I'm not sure how common
that notation is.
Thanks. Markus Bertheau also supplied this solution:
SELECT enddate, count(*) FROM (
SELECT date_trunc('day', endtime) AS enddate FROM eg_event WHERE
endtime >= '2006-01-01' and endtime < '2006-03-01') as foo
GROUP BY enddate
ORDER BY enddate
It brings up a question though: is there any way in Postgres to set a "quirks" or "standards" mode. Or get Postgres to log the compliance level of each command and command element used, e,g.:
ORDER BY n
|
SQL92
|
GROUP BY n
|
PSQL
|
(SELECT ...)
|
SQL99
|
SELECT
|
SQL99
|
count(...)
|
SQL99
|
date_trunc(string,...)
|
PQSL
|
It is so easy to get lazy and start shrink-wrapping code to the database. That's certainly why mysql SQL tends to be so non-portable....