Welcome to ORDER BY jungle
Bare names and expressions in ORDER BY go through two different parsers in PostgreSQL. The boundary between them is one if-statement old enough to vote, and it shows up in places you would not expect.
boringSQL | Supercharge your SQL & PostgreSQL powers ยท Radim Marek