Quantcast
Channel: TimescaleDB and PostgreSQL - Timescale Community Forum
Viewing all articles
Browse latest Browse all 291

Building a continuous aggregate on a continuous aggregate on a continuous aggregate

$
0
0

CREATE MATERIALIZED VIEW daily_element_views
WITH (timescaledb.continuous) AS
SELECT
company_uuid,
site_9char,
page_9char,
element_9char,
time_bucket(‘1 day’, view_start, ‘PDT’) AS element_date,
COUNT(*) AS total_views
FROM
view
GROUP BY
company_uuid,
site_9char,
page_9char,
element_9char,
element_date;

CREATE MATERIALIZED VIEW daily_page_views
WITH (timescaledb.continuous) AS
SELECT
company_uuid,
site_9char,
page_9char,
time_bucket(‘1 day’, element_date, ‘PDT’) AS page_date,
COUNT(*) AS total_views
FROM
daily_element_views
GROUP BY
company_uuid,
site_9char,
page_9char,
page_date;

CREATE MATERIALIZED VIEW daily_site_views
WITH (timescaledb.continuous) AS
SELECT
company_uuid,
site_9char,
time_bucket(‘1 day’, page_date, ‘PDT’) AS site_date,
COUNT(*) AS total_views
FROM
daily_page_views
GROUP BY
company_uuid,
site_9char,
site_date;

Attempting to create ‘daily_site_views’ on top of ‘daily_page_views’ which throws this error: “ERROR: time bucket function must reference a hypertable dimension column”.
Can’t figure out why this is happening as ‘daily_page_views’ is an aggregate on an aggregate itself so why wouldn’t I be able to add another layer to that?

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 291

Trending Articles