【问题标题】:Calculated fields on timescale时间尺度上的计算字段
【发布时间】:2019-09-04 06:22:12
【问题描述】:

我正在尝试使用传感器数据将计算字段添加到我的超表中,例如,我想添加体积读数的导数以获得体积流量。

我尝试使用连续聚合来执行此操作,但我得到了invalid SELECT query for continuous aggregate

create view public.readings_raw_with_calc_fields
WITH (timescaledb.continuous)
as
select 
serial,
time,
type,
value
from public.readings_raw
union all
select 
serial,
time,
'Volume flow calc.' as type,
(lead(value) over (partition by serial,devicetype,manufacturer order by time))-value as value
from 
public.readings_raw
where type='Volume'

这是因为lead 函数还是因为连续聚合中必须有聚合函数?什么是最好的做法?我可以做一个每分钟在原始表中插入数据的工作,但是如果新数据被及时插入,我就无法捕捉到(这是一个相当大的表,所以我不能每分钟都遍历整个表)。

【问题讨论】:

    标签: sql postgresql timescaledb


    【解决方案1】:

    窗口函数和 UNION 都会阻止连续聚合的工作。

    在这种情况下,由于每行执行的计算非常低,时间索引和常规视图可能会提供所需的性能。

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2017-02-28
      • 2013-05-20
      • 2021-06-23
      • 2021-12-31
      • 2021-12-29
      相关资源
      最近更新 更多