【问题标题】:how to time_bucket by month with timescaleDB如何使用 timescaleDB 按月计算 time_bucket
【发布时间】:2019-11-24 04:58:59
【问题描述】:

关于这个问题,我知道有一个open feature request 可以将月份/年份添加到 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)

实现这一目标的最佳方法是什么?

谢谢!

【问题讨论】:

  • 我遇到了同样的问题,很遗憾 Timescale 没有响应社区的请求。你是怎么解决这个问题的?

标签: postgresql typeorm timescaledb


【解决方案1】:

看起来他们计划在未来支持此功能,但尚未包含在任何里程碑的计划中,请查看 https://github.com/timescale/timescaledb/issues/414

目前,我使用time_bucket('1 day', timestamp) 做一个解决方法,或者将其作为CTE / with 的一部分,我将调用date_trunc('month', time_bucketed_day_column)。这样,timescaledb从较小interfal(天)的gapfill函数应该在较长的时间间隔上进行。

【讨论】:

猜你喜欢
  • 2019-11-01
  • 2021-12-14
  • 2018-06-12
  • 1970-01-01
  • 2019-04-17
  • 2021-04-26
  • 2021-11-30
  • 2011-03-24
  • 2013-04-07
相关资源
最近更新 更多