从这个问题开始,我知道有一个open feature request将月份/年份添加到time_bucket函数中。
我的问题是,现在完成此任务的最佳方法是什么。本期提到date_trunc
这是两种方法:
SELECT time_bucket('1 week', timestamp) AS "one_week",
count(*) AS "count",
first(value, timestamp) AS "first",
last(value, timestamp) AS "last"
FROM "event" "event"
WHERE event."signalId" = $1
GROUP BY one_week
ORDER BY one_week DESC
SELECT date_trunc('month', timestamp) AS "one_month",
count(*) AS "count",
first(value, timestamp) AS "first",
last(value, timestamp) AS "last"
FROM "event" "event"
WHERE event."signalId" = $1
GROUP BY one_month
ORDER BY one_month DESC
这两项工作均符合预期(尽管我尚未进行任何性能测试)。
我想实现:
实现此目标的最佳方法是什么?
谢谢!
答案 0 :(得分:0)
看起来他们计划将来支持此功能,但尚未计划任何里程碑,请检查 https://github.com/timescale/timescaledb/issues/414
现在,我使用time_bucket('1 day', timestamp)
进行变通,或者将其包含在CTE / with
中,从中调用on date_trunc('month', time_bucketed_day_column)
。这样,应该在更长的时间间隔内使用较小的间隔(天)中的timescaledb的gapfill函数。