window function
A calculation across a set of rows related to the current row that, unlike GROUP BY, keeps every input row in the answer.
In more detail
Adding OVER to a function turns it into a window function, so each order row can carry its customer's order count or a running total. That replaces fetching rows and looping over them in application code, and saves round trips.
Related terms
- OVER — The clause that makes a function a window function and defines which rows it can see and in what order.
- PARTITION BY — The part of OVER that splits rows into groups so a window calculation restarts for each group.
- window frame — The subset of a partition that a window calculation sees for each row, such as the current row and the one before it.
- ROW_NUMBER — A window function that numbers rows 1, 2, 3 in the window's order, giving tied rows different numbers.
- GROUP BY — The clause that splits rows into groups sharing the same values, so aggregates return one result per group.
Taught in
- Ordering And Limiting Results — PostgreSQL, Indexing & Relational Data Modeling
- Window Functions: Replacing Application Loops — PostgreSQL, Indexing & Relational Data Modeling
- Advanced Window Functions: Ranking And Framing — PostgreSQL, Indexing & Relational Data Modeling