我正在尝试使用 TimescaleDB 扩展来计算一些连续聚合。我有这个工作正常的查询:
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
当我尝试将其放在连续聚合物化视图中时,出现错误:
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
我得到的错误是:
ERROR: invalid continuous aggregate view
SQL state: 0A000
TimescaleDB 是否允许按时间窗口在分区上进行连续聚合?
我在 PostgreSQL 12.5 上使用 TimescaleDB 2.1。