Consider a table with 2 columns:
create table foo
(
ts timestamp,
precipitation numeric,
primary key (ts)
);
with the following data:
| ts | precipitation |
|---|---|
| 2021-06-01 12:00:00 | 1 |
| 2021-06-01 13:00:00 | 0 |
| 2021-06-01 14:00:00 | 2 |
| 2021-06-01 15:00:00 | 3 |
I would like to use a TimescaleDB continuous aggregate to calculate a three hour cumulative sum of this data that is calculated once per hour. Using the example data above, my continuous aggregate would contain
| ts | cum_precipitation |
|---|---|
| 2021-06-01 12:00:00 | 1 |
| 2021-06-01 13:00:00 | 1 |
| 2021-06-01 14:00:00 | 3 |
| 2021-06-01 15:00:00 | 5 |
I can't see a way to do this with the supported syntax for continuous aggregrates. Am I missing something? Essentially, I would like the time bucket to be the preceding x hours, but the calculation to occur hourly.