New answers tagged

3 votes
Accepted

Understanding the Impact of ORDER BY in Window Functions on other Partitions in PostgreSQL

Think of your data as a pile of clothes, where the odd column stores the id of a type of clothing (shirt, pants, socks, etc). The PARTITION clause on odd is the equivalent of organizing the clothes ...
J.D.'s user avatar
  • 35.2k
2 votes

Understanding the Impact of ORDER BY in Window Functions on other Partitions in PostgreSQL

Without the ORDER BY, the expression is underdetermined. There are multiple possible answers, of which it returns the most convenient to compute. Once one expression gains an ORDER BY, then it ...
jjanes's user avatar
  • 38.7k
0 votes

Window functions and distinct

You can use a combination of window functions and normal group by on the same partitioning, rather than using distinct. This means the optimizer can rely on the required sort not changing. You can use ...
Charlieface's user avatar
  • 11.8k
1 vote
Accepted

Window functions and distinct

Instead of using window functions, which don't reduce the number of result rows, and then DISTINCT, which does, it would be better to use aggregate functions that do both in a single step. We need ...
Laurenz Albe's user avatar

Top 50 recent answers are included