I just switched from mysql to postgres (yay!) but now on my postgres server (only) I’m getting an error that:
SELECT DISTINCT, ORDER BY expressions must appear in select list
It’s the same query:
SELECT DISTINCT * FROM table ORDER BY '?'
BTW this is a query auto-generated by django. Alternatively, any way to get django to actually render correct sql?
Addendum
It turns out that for whatever reason, with my Postgres 8.4 production server, Django was quashing the error, while with my Postgres 9.0 dev server it was not. I have no idea if it was related to the Postgres versions or not, but it WAS in fact erroring in both Postgreses and NOT in MySQL.
As @Catcall said, technically this statement is illegal and nonsensical in SQL.
However, MySQL and SQLite allow you to do a
SELECT DISTINCT id FROM test ORDER BY whatever, while PostgreSQL does not. It’s as simple as that.MySQL and SQLite may produce non-deterministic results using this method, I’m not sure.
However if you are ordering by
'?', it should be fine.