【发布时间】:2021-01-11 23:11:55
【问题描述】:
我对 Grafana 和 Postgres 还很陌生,可以在这方面寻求帮助。我在 PostgreSQL 中有一个带有温度预测的数据集。同一参考日期在全天不同时间点发布多个预测(由dump_date 表示)。假设:今天 06:00 和今天 12:00 发布明天的预测(时间由 start_time 指示)。现在我想使用 Grafana 将温度预测可视化为时间序列。但是,我只想可视化最新发布的预测(12:00),而不是两个预测。我以为我会使用 DISTINCT ON() 仅从该数据集中选择最新发布的预测,但不知何故,对于 Grafana,这没有响应。我在 Grafana 中的代码如下:
SELECT
$__time(distinct on(t_ID.start_time)),
concat('Forecast')::text as metric,
t_ID.value
FROM
forecast_table t_ID
WHERE
$__timeFilter(t_ID.start_time)
and t_ID.start_time >= (current_timestamp - interval '30 minute')
and t_ID.dump_date >= (current_timestamp - interval '30 minute')
ORDER BY
t_ID.start_time asc,
t_ID.dump_date desc
但这不起作用,因为我收到消息:'AS 处或附近的语法错误'。我该怎么办?
【问题讨论】:
-
什么是
$__time?
标签: postgresql time-series grafana distinct-on