News for hackers. Stuff that matters.
Re:SQL Anti-Patterns You Should Avoid by ryandv on Saturday October 18, 2025 @12:33PM (#45628561)
PostgreSQL's `DISTINCT ON` extension is useful for navigating bitemporal data in which I want, for example, the latest recorded version of an entry, for each day of the year.

There are few other legitimate use cases of the regular `DISTINCT` that I have seen, other than the typical one-off `SELECT DISTINCT(foo) FROM bar`.

Re:SQL Anti-Patterns You Should Avoid by dotancohen on Saturday October 18, 2025 @12:48PM (#45628652)
Without DISTINCT ON (which I've never used) you can use a window function via the OVER clause with PARTITION BY. I'm pretty sure that's standard SQL.
Re:SQL Anti-Patterns You Should Avoid by ryandv on Saturday October 18, 2025 @12:49PM (#45628656)
Yes, this is the implementation I have seen in other dialects.