sql - 时间尺度上的计算字段
问题描述
我正在尝试使用传感器数据将计算字段添加到我的超表中,例如,我想添加体积读数的导数以获得体积流量。
我试图用一个连续的聚合来做到这一点,但我得到了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
函数还是因为连续聚合中必须有聚合函数?什么是最好的做法?我可以做一个每分钟在原始表中插入数据的工作,但是如果新数据被及时插入,我就无法捕捉到(这是一个相当大的表,所以我不能每分钟都遍历整个表)。
解决方案
窗口函数和 UNION 都将阻止连续聚合工作。
在这种情况下,由于每行执行的计算非常低,时间索引和常规视图可以提供所需的性能。
推荐阅读
- javascript - 如何在反应中创建动态css类
- javascript - Animate.css 动画 fadeInDown 在添加 @angular/material 后停止工作
- mysql - SQL:显示两个表的结果
- linux - 扫描并合并大文件中的两行(> 5 Gb)
- typescript - 我是否必须验证打字稿重载中的每个参数?
- python - 使用 BeautifulSoup 抓取 XML 文件的标签和属性
- python - 将变量值添加到 mysql 列
- javascript - Rails + StimulusJS 动态创建的选择菜单不起作用
- r - solnp() 中的 sol$convergence = 1 或 2 是什么意思?
- elasticsearch - Elasticsearch - 嵌套字段排序