Remix.run Logo
ryandv 15 hours ago

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`.

dotancohen 15 hours ago | parent [-]

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.

ryandv 15 hours ago | parent [-]

Yes, this is the implementation I have seen in other dialects.