Skip to content

Commit 1244afe

Browse files
46bitirvinebroque
andauthored
DS-15647 DS-15648: Document aggregate-if and date/time function additions to the WAE SQL API (#26101)
* DS-15647 DS-15648: Document aggregate-if and date/time function additions to the WAE SQL API This commit adds the following function additions to the docs: - `countIf` - `sumIf` - `avgIf` - `toYear` - `toMonth` - `toDayOfMonth` - `toHour` - `toMinute` - `toSecond` - `toStartOfYear` - `toStartOfMonth` - `toStartOfDay` - `toStartOfHour` - `toStartOfFifteenMinutes` - `toStartOfMinute` - `today` This commit reorders the date/time docs page to be in approximate alphabetical order, which works much better than just appending the functions to the end. * DS-15648: Document further date/time function additions to the WAE SQL API These are some assorted functions commonly used by LLMs: - `toDayOfWeek` - `toStartOfWeek` - `toStartOfTenMinutes` - `toStartOfFiveMinutes` - `toYYYYMM` * Add changelog for further WAE SQL additions This commit adds a changelog entry for recent function additions, as documented in the previous commits. I have chosen to omit descriptions of the date/time functions, because they are all quite generic and it looks unwieldy to have some many samey descriptions. * Update src/content/changelog/workers/2025-11-12-analytics-engine-further-sql-enhancements.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> --------- Co-authored-by: Brendan Irvine-Broque <[email protected]>
1 parent 4450c5c commit 1244afe

File tree

3 files changed

+439
-21
lines changed

3 files changed

+439
-21
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: More SQL aggregate, date and time functions available in Workers Analytics Engine
3+
description: Workers Analytics Engine now supports more SQL functions for aggregation and for working with dates and times
4+
date: 2025-11-12
5+
products:
6+
- workers-analytics-engine
7+
---
8+
You can now perform more powerful queries directly in [Workers Analytics Engine](https://developers.cloudflare.com/analytics/analytics-engine/) with a major expansion of our SQL function library.
9+
10+
Workers Analytics Engine allows you to ingest and store high-cardinality data at scale (such as custom analytics) and query your data through a simple SQL API.
11+
12+
Today, we've expanded Workers Analytics Engine's SQL capabilities with several new functions:
13+
14+
[**New aggregate functions:**](https://developers.cloudflare.com/analytics/analytics-engine/sql-reference/aggregate-functions/)
15+
- `countIf()` - count the number of rows which satisfy a provided condition
16+
- `sumIf()` - calculate a sum from rows which satisfy a provided condition
17+
- `avgIf()` - calculate an average from rows which satisfy a provided condition
18+
19+
[**New date and time functions:**](https://developers.cloudflare.com/analytics/analytics-engine/sql-reference/date-time-functions/)
20+
- `toYear()`
21+
- `toMonth()`
22+
- `toDayOfMonth()`
23+
- `toDayOfWeek()`
24+
- `toHour()`
25+
- `toMinute()`
26+
- `toSecond()`
27+
- `toStartOfYear()`
28+
- `toStartOfMonth()`
29+
- `toStartOfWeek()`
30+
- `toStartOfDay()`
31+
- `toStartOfHour()`
32+
- `toStartOfFifteenMinutes()`
33+
- `toStartOfTenMinutes()`
34+
- `toStartOfFiveMinutes()`
35+
- `toStartOfMinute()`
36+
- `today()`
37+
- `toYYYYMM()`
38+
39+
## Ready to get started?
40+
Whether you're building usage-based billing systems, customer analytics dashboards, or other custom analytics, these functions let you get the most out of your data. [Get started ](/analytics/analytics-engine/get-started/) with Workers Analytics Engine and explore all available functions in our [SQL reference documentation](/analytics/analytics-engine/sql-reference/).

src/content/docs/analytics/analytics-engine/sql-reference/aggregate-functions.mdx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,57 @@ SELECT topKWeighted(double1, _sample_interval) FROM my_dataset
248248
-- find the 15 most common values of <blob1>, weighted by `_sample_interval`
249249
SELECT topKWeighted(15)(blob1, _sample_interval) FROM my_dataset
250250
```
251+
252+
## countIf <Badge text="New" variant="tip" size="small" />
253+
254+
Usage:
255+
256+
```sql
257+
countIf(<expr>)
258+
```
259+
260+
`countIf` is an aggregation function that returns the number of rows in the results set,
261+
but only counting rows where a provided expression evaluates to true.
262+
263+
Example:
264+
265+
```sql
266+
-- return the number of rows where `double1` is greater than 5
267+
countIf(double1 > 5)
268+
```
269+
270+
## sumIf <Badge text="New" variant="tip" size="small" />
271+
272+
Usage:
273+
274+
```sql
275+
sumIf(<expr>, <expr>)
276+
```
277+
278+
`sumIf` is an aggregation function that returns the sum of a first expression across all rows in the results set,
279+
but only including rows where a second expression evaluates to true.
280+
281+
Example:
282+
283+
```sql
284+
-- return the sum of column `item_cost` of all items where another column `in_stock` is not zero
285+
sumIf(item_cost, in_stock > 0)
286+
```
287+
288+
## avgIf <Badge text="New" variant="tip" size="small" />
289+
290+
Usage:
291+
292+
```sql
293+
avgIf(<expr>, <expr>)
294+
```
295+
296+
`avgIf` is an aggregation function that returns the mean of an expression across all rows in the results set,
297+
but only including rows where a second expression evaluates to true.
298+
299+
Example:
300+
301+
```sql
302+
-- return the mean of column `item_cost` where another column `in_stock` is not zero
303+
avgIf(item_cost, in_stock > 0)
304+
```

0 commit comments

Comments
 (0)