Expand description
Window functions support.
This module provides types for building window functions (OVER clauses) across different database backends.
§Supported Features
| Feature | PostgreSQL | MySQL | SQLite | MSSQL | MongoDB 5.0+ |
|---|---|---|---|---|---|
| ROW_NUMBER | ✅ | ✅ | ✅ | ✅ | ✅ |
| RANK/DENSE_RANK | ✅ | ✅ | ✅ | ✅ | ✅ |
| LAG/LEAD | ✅ | ✅ | ✅ | ✅ | ✅ |
| Frame clauses | ✅ | ✅ | ✅ | ✅ | ✅ |
| Named windows | ✅ | ✅ | ✅ | ❌ | ❌ |
§Example Usage
ⓘ
use prax_query::window::{WindowFunction, WindowSpec, row_number, rank, sum};
// ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC)
let wf = row_number()
.over(WindowSpec::new()
.partition_by(["dept"])
.order_by("salary", SortOrder::Desc));
// Running total
let running = sum("amount")
.over(WindowSpec::new()
.order_by("date", SortOrder::Asc)
.rows_unbounded_preceding());Modules§
- mongodb
- MongoDB $setWindowFields support.
Structs§
- Frame
Clause - Frame clause for window functions.
- Named
Window - A named window definition.
- Order
Spec - Order specification for window functions.
- Window
Function - A window function with its OVER clause.
- Window
Function Builder - Builder for window functions.
- Window
Spec - Window specification (OVER clause).
Enums§
- Frame
Bound - Frame boundary.
- Frame
Exclude - Frame exclusion (PostgreSQL).
- Frame
Type - Frame type.
- Nulls
Position - Position of NULL values in ordering.
- Window
Fn - Available window functions.
Functions§
- avg
- Create AVG() window function.
- count
- Create COUNT() window function.
- cume_
dist - Create CUME_DIST() window function.
- custom
- Create a custom window function.
- dense_
rank - Create DENSE_RANK() window function.
- first_
value - Create FIRST_VALUE() window function.
- lag
- Create LAG() window function.
- lag_
full - Create LAG() with offset and default.
- lag_
offset - Create LAG() with offset.
- last_
value - Create LAST_VALUE() window function.
- lead
- Create LEAD() window function.
- lead_
full - Create LEAD() with offset and default.
- lead_
offset - Create LEAD() with offset.
- max
- Create MAX() window function.
- min
- Create MIN() window function.
- nth_
value - Create NTH_VALUE() window function.
- ntile
- Create NTILE(n) window function.
- percent_
rank - Create PERCENT_RANK() window function.
- rank
- Create RANK() window function.
- row_
number - Create ROW_NUMBER() window function.
- sum
- Create SUM() window function.