Welcome to ORDER BY jungle

· Radim Marek · May 15, 2026, 10:07 a.m.
Summary
This blog post explores the complexities of SQL's ORDER BY clause in PostgreSQL, highlighting how different types of identifiers and expressions affect the sorting of query results. Through specific examples, the author, Radim Marek, explains the subtle differences in how the parser interprets column names, aliases, and expressions, revealing common pitfalls that developers may encounter. The conclusion emphasizes the importance of understanding these distinctions to avoid unexpected results in SQL queries.
AUTHOR
Sponsored
Zulip logo Zulip
Organized team chat for people who take work seriously. Topic-based threading keeps conversations focused.
Try Zulip
Become a sponsor →
BLOG POST FEATURED ON

Add this plugin to your blog