2

我有这张series桌子和它的超表。我想对该表中的数据进行不同的连续聚合。

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.

甚至不可能在同一张表上创建不同的超表。

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或者我应该使用另一种方法(例如,每个连续聚合的重复表:-x)?

4

1 回答 1

3

从 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;
于 2019-06-20T07:02:40.367 回答