Skip to content

Commit 8c1e942

Browse files
committed
docs: clarify boundary behavior in ROWS BETWEEN
- Add detailed explanation of window frame behavior at partition boundaries - Include examples showing how windows shrink at edges - Address common confusion about window size at start/end of partitions
1 parent 4a7467a commit 8c1e942

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/en/sql-reference/20-sql-functions/08-window-functions/rows-between.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,29 @@ AVG(column) OVER (ORDER BY sort_col ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
237237
3. **Consider performance** with large windows - smaller windows are more efficient
238238
4. **Handle edge cases** - windows may be smaller at partition boundaries
239239
5. **Combine with PARTITION BY** for per-group calculations
240+
6. **Understand boundary behavior** - windows shrink at partition edges
241+
242+
### Boundary Behavior Examples
243+
244+
**Centered window at partition edges:**
245+
```sql
246+
-- For row 1: ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
247+
-- Actual window: CURRENT ROW AND 1 FOLLOWING (no preceding row exists)
248+
249+
-- For last row: ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
250+
-- Actual window: 1 PRECEDING AND CURRENT ROW (no following row exists)
251+
```
252+
253+
**Moving average at start:**
254+
```sql
255+
-- For row 1: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
256+
-- Actual window: CURRENT ROW only (no preceding rows)
257+
258+
-- For row 2: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
259+
-- Actual window: 1 PRECEDING AND CURRENT ROW (only 1 preceding row exists)
260+
```
261+
262+
This is normal behavior - the window frame adapts to available rows at partition boundaries.
240263

241264
## Limitations
242265

0 commit comments

Comments
 (0)