Welcome to ORDER BY jungle
Summary
This post explains PostgreSQL's ORDER BY resolution in depth, showing how bare identifiers, aliases, and expressions can trigger different parsing paths (SQL92 vs SQL99). It includes practical examples and warns about surprising edge cases, offering a workaround to force predictable behavior.