We can't append the ordering clause to select for distinct(*fields) - that would mean having more than one field in the subquery's SELECT clause and that doesn't work. I also added a link to PostgreSQL mailing list to clarify why exactly we need to add ordering SQL into select clause in DISTINCT case. This was the best reference I could find.