SQL’s ORDER BY Has Come a Long Way
8 points by radim
8 points by radim
Haven’t realised how SQL standard handles ORDER BY on non-selected columns by just rewriting the SELECT clause behind your back.
Separation of concerns ruthlessly broken ;-)))
(just sharing as I commented same on HN - need to stop that)
If only it were that simple :S
postgres=# select -a as a from nums order by a;
a
----
-3
-2
-1
0
(4 rows)
postgres=# select -a as a from nums order by -a;
a
----
-3
-2
-1
0
(4 rows)
postgres=# select a as c from nums order by a;
c
---
(0 rows)
postgres=# select a as c from nums order by -a;
c
---
(0 rows)
postgres=# select a as c from nums order by c;
c
---
(0 rows)
postgres=# select a as c from nums order by -c;
ERROR: column "c" does not exist
LINE 1: select a as c from nums order by -c;
^