I am trying to use the TimescaleDB extension to compute some continuous aggregates. I have this query which works fine:
SELECT distinct time_bucket('1 hour', entry_ts) as date_hour,
type_id,
entry_id,
exit_id,
count(*) OVER (partition by time_bucket('1 hour', entry_ts), entry_id, exit_id, type_id) AS total,
((count(*) over (partition by time_bucket('1 hour', entry_ts), entry_id, exit_id, type_id)) * 100)::numeric /
(count(*) over (partition by time_bucket('1 hour', entry_ts), entry_id)) percentage_of_entry
FROM transits
When I try to put this inside a continuous aggregate materialized view, I get an error:
CREATE MATERIALIZED VIEW transits_hourly
WITH (timescaledb.continuous) AS
SELECT distinct time_bucket('1 hour', entry_ts) as date_hour,
type_id,
entry_id,
exit_id,
count(*) OVER (partition by time_bucket('1 hour', entry_ts), entry_id, exit_id, type_id) AS total,
((count(*) over (partition by time_bucket('1 hour', entry_ts), entry_id, exit_id, type_id)) * 100)::numeric /
(count(*) over (partition by time_bucket('1 hour', entry_ts), entry_id)) percentage_of_entry
FROM transits
WITH NO DATA
The error I get is:
ERROR: invalid continuous aggregate view
SQL state: 0A000
Does TimescaleDB allow Continuous Aggregates over Partition By time windows?
I am using TimescaleDB 2.1 on PostgreSQL 12.5.