Create a window function
To use a window function in a continuous aggregate:
Create a simple table with to store a value at a specific time:
Enable window functions.
As window functions are experimental, in order to create continuous aggregates with window functions. you have to enable_cagg_window_functions.
- Bucket your data by
timeand calculate the delta between time buckets using thelagwindow function:
Window functions must stay within the time bucket. Any query that tries to look beyond the current time bucket will produce incorrect results around the refresh boundaries.
Window functions that partition by time_bucket should be safe even with LAG()/LEAD()