You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dev/update_function_docs.sh
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,25 @@ dev/update_function_docs.sh file for updating surrounding text.
59
59
# Aggregate Functions
60
60
61
61
Aggregate functions operate on a set of values to compute a single result.
62
+
63
+
## Filter clause
64
+
65
+
Aggregate functions support the SQL `FILTER (WHERE ...)` clause to restrict which input rows contribute to the aggregate result.
66
+
67
+
```sql
68
+
function([exprs]) FILTER (WHERE condition)
69
+
```
70
+
71
+
Example:
72
+
73
+
```sql
74
+
SELECT
75
+
sum(salary) FILTER (WHERE salary > 0) AS sum_positive_salaries,
76
+
count(*) FILTER (WHERE active) AS active_count
77
+
FROM employees;
78
+
```
79
+
80
+
Note: When no rows pass the filter, `COUNT` returns `0` while `SUM`/`AVG`/`MIN`/`MAX` return `NULL`.
62
81
EOF
63
82
64
83
echo"Running CLI and inserting aggregate function docs table"
@@ -266,6 +285,17 @@ where **offset** is an non-negative integer.
266
285
267
286
RANGE and GROUPS modes require an ORDER BY clause (with RANGE the ORDER BY must specify exactly one column).
268
287
288
+
## Filter clause for aggregate window functions
289
+
290
+
Aggregate window functions support the SQL `FILTER (WHERE ...)` clause to include only rows that satisfy the predicate from the window frame in the aggregation.
291
+
292
+
```sql
293
+
sum(salary) FILTER (WHERE salary > 0)
294
+
OVER (PARTITION BY depname ORDER BY salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
295
+
```
296
+
297
+
If no rows in the frame satisfy the filter for a given output row, `COUNT` yields `0` while `SUM`/`AVG`/`MIN`/`MAX` yield `NULL`.
298
+
269
299
## Aggregate functions
270
300
271
301
All [aggregate functions](aggregate_functions.md) can be used as window functions.
Copy file name to clipboardExpand all lines: docs/source/user-guide/sql/window_functions.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,6 +145,17 @@ where **offset** is an non-negative integer.
145
145
146
146
RANGE and GROUPS modes require an ORDER BY clause (with RANGE the ORDER BY must specify exactly one column).
147
147
148
+
## Filter clause for aggregate window functions
149
+
150
+
Aggregate window functions support the SQL `FILTER (WHERE ...)` clause to include only rows that satisfy the predicate from the window frame in the aggregation.
151
+
152
+
```sql
153
+
sum(salary) FILTER (WHERE salary >0)
154
+
OVER (PARTITION BY depname ORDER BY salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
155
+
```
156
+
157
+
If no rows in the frame satisfy the filter for a given output row, `COUNT` yields `0` while `SUM`/`AVG`/`MIN`/`MAX` yield `NULL`.
158
+
148
159
## Aggregate functions
149
160
150
161
All [aggregate functions](aggregate_functions.md) can be used as window functions.
0 commit comments