1.3.6.2. TSDB 支持的函数
函数 |
influxdb1 支持情况 |
influxdb3 支持情况 |
|---|---|---|
sum |
无差异 |
无差异 |
count |
无差异 |
无差异 |
avg |
需转换 avg聚合函数 |
无差异 |
min |
无差异 |
无差异 |
max |
无差异 |
无差异 |
cast(expr as double) |
不支持 |
无差异 |
convert_tz |
需转换 时区转换 |
需转换 时区转换 |
selector_last(x, time)['time'/'value'] |
无差异 |
|
selector_first(x, time)['time'/'value'] |
无差异 |
|
COALESCE/locf/interpolate(只用于填充缺失值) |
需转换 时间间隔分区 |
无差异 |
下面是个别复杂函数介绍:
1.3.6.2.1. select_first, select_last 聚合函数
描述
select_first, select_last 同influxql 的 first, last。用于取时间范围内的第一个和最后一个字段值。 INFLUXDB3 语法。
语法
支持的格式如下(同influxdb3):
-- INFLUXBD3 SQL
select_first(expr, time)['time']
select_first(expr, time)['value']
select_last(expr, time)['time']
select_last(expr, time)['value']
示例
select tz(selector_first(my_field, time)['time'], 'Asia/Shanghai') as _time,
selector_first(my_field, time)['value']
from base_test
where my_tag='val7'
and time <= '1970-01-10T00:00:00Z'
and time >= '1970-01-01T00:00:00Z'
order by time
select tz(selector_last(my_field, time)['time'], 'Asia/Shanghai') as _time,
selector_last(my_field, time)['value']
from base_test
where my_tag='val7'
and time <= '1970-01-10T00:00:00Z'
and time >= '1970-01-01T00:00:00Z'
order by time
1.3.6.2.2. COALESCE/locf/interpolate(只用于填充缺失值)
描述
COALESCE/locf/interpolate(只用于填充缺失值),INFLUXDB3 语法
语法
支持的格式如下(同influxdb3):
SELECT date_bin_gapfill(intervalExpr, time) as alias_name,
expr_with_fill_func...
FROM table [WHERE condition]
GROUP BY alias_name, expr...
[ ORDER BY ... ]
fill_func: locf|interpolate|coalesce
1.3.6.2.3. convert_tz 时区转换
描述
用于转换时区,MYSQL 语法
语法
支持的格式如下:
convert_tz(expr, 'UTC', 'timezone')
警告
源时区必须为'UTC'