就这个问题而言,我知道有一个开放的功能请求可以将月份/年份添加到 time_bucket 函数中。
我的问题是,现在实现这一目标的最佳方法是什么。这个问题提到date_trunc
以下是两种方法:
timescaledb 的 time_bucket
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
postgres date_trunc
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
这两个都按预期工作(尽管我没有进行任何性能测试)。
我想实现:
- (a) gapfill(如 timescaledb time_bucket_gapfill,以及
- (b) 最后一个值结转 (locf)
实现这一目标的最佳方法是什么?
谢谢!