Version: 10.0
As I understand it, the only valid constant datatype in an ORDER BY is integer. That's validated by the following test:
jordan=# SELECT * FROM t ORDER BY 'foo';
ERROR: non-integer constant in ORDER BY
LINE 1: SELECT * FROM t ORDER BY 'foo';
However, using a prepared statement, this behavior can be avoided:
jordan=# PREPARE x as SELECT * FROM t ORDER BY $1;
PREPARE
jordan=# EXECUTE x('foo');
c
---
1
It seems to me that there is some missing type checking from ORDER BY.