如何在 TimescaleDB 中在一个 table 上创建多个连续聚合?
How to create multiple continuous aggregates over one table in TimescaleDB?
我有这个 series
table 及其 hypertable。我想在此 table.
中对数据进行不同的连续聚合
CREATE TABLE series (
time TIMESTAMPTZ PRIMARY KEY,
value INTEGER
);
SELECT create_hypertable('series', 'time');
CREATE VIEW mat_view1
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 day', time) AS day,
AVG(value)
FROM series
GROUP BY day;
CREATE VIEW mat_view2
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 week', time) AS week,
COUNT(value)
FROM series
GROUP BY week;
但在 PostgreSQL 11 中似乎不可能 - 这是我在 运行 上面的查询时得到的结果:
ERROR: hypertable already has a continuous aggregate
RECOMMENDATION: hypertables currently only support a single continuous aggregate. Drop the other continuous aggreagate to add a new one.
甚至不可能在相同的 table 上创建不同的 hypertable。
ERROR: hypertable already has a continuous aggregate
RECOMMENDATION: hypertables currently only support a single continuous aggregate. Drop the other continuous aggreagate to add a new one.
是否可以解决此限制?或者我应该使用另一种方法(例如,为每个连续聚合复制 series
table :-x)?
从 TimescaleDB 1.4.0 开始支持,请参阅:
https://github.com/timescale/timescaledb/blob/master/CHANGELOG.md#140-2019-07-18
以前 Timescale 不支持此功能,但您可以执行以下操作:创建 1 个连续聚合,其中包含您可能需要的所有详细信息,并为第二个用例创建常规视图。
CREATE VIEW mat_view1
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 day', time) AS day,
AVG(value) AS avg,
COUNT(value) AS count
FROM series
GROUP BY day;
CREATE VIEW view2 AS
SELECT time_bucket('1 week', day) AS week,
SUM(count) AS count
FROM mat_view1
GROUP BY week;
我有这个 series
table 及其 hypertable。我想在此 table.
CREATE TABLE series (
time TIMESTAMPTZ PRIMARY KEY,
value INTEGER
);
SELECT create_hypertable('series', 'time');
CREATE VIEW mat_view1
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 day', time) AS day,
AVG(value)
FROM series
GROUP BY day;
CREATE VIEW mat_view2
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 week', time) AS week,
COUNT(value)
FROM series
GROUP BY week;
但在 PostgreSQL 11 中似乎不可能 - 这是我在 运行 上面的查询时得到的结果:
ERROR: hypertable already has a continuous aggregate
RECOMMENDATION: hypertables currently only support a single continuous aggregate. Drop the other continuous aggreagate to add a new one.
甚至不可能在相同的 table 上创建不同的 hypertable。
ERROR: hypertable already has a continuous aggregate
RECOMMENDATION: hypertables currently only support a single continuous aggregate. Drop the other continuous aggreagate to add a new one.
是否可以解决此限制?或者我应该使用另一种方法(例如,为每个连续聚合复制 series
table :-x)?
从 TimescaleDB 1.4.0 开始支持,请参阅: https://github.com/timescale/timescaledb/blob/master/CHANGELOG.md#140-2019-07-18
以前 Timescale 不支持此功能,但您可以执行以下操作:创建 1 个连续聚合,其中包含您可能需要的所有详细信息,并为第二个用例创建常规视图。
CREATE VIEW mat_view1
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 day', time) AS day,
AVG(value) AS avg,
COUNT(value) AS count
FROM series
GROUP BY day;
CREATE VIEW view2 AS
SELECT time_bucket('1 week', day) AS week,
SUM(count) AS count
FROM mat_view1
GROUP BY week;