SELECT ... INTO ... 语句允许您将查询结果集写回到指定序列上。
下面是 select 语句的语法定义:
selectClause intoClause? fromClause whereClause? specialClause?
如果去除 intoClause 子句,那么 select 语句即是单纯的查询语句。
intoClause 子句是写回功能的标记语句。
下面是 intoClause 子句的定义:
intoClause : INTO intoPath (COMMA intoPath)* ; intoPath : fullPath | nodeNameWithoutStar (DOT nodeNameWithoutStar)* ;
intoPath(目标序列)支持两种方式指定:
以 root 开头的完整序列名指定
例子:
select s1, s1 into root.sg.d1.t1, root.sg.d1.t2 from root.sg.d1
不以 root 开头的部分序列名指定,此时目标序列由 from 子句中的序列前缀和intoPath拼接而成
例子:
select s1, s1 into t1, t2 from root.sg.d1
这等价于
select s1, s1 into root.sg.d1.t1, root.sg.d1.t2 from root.sg.d1
在intoPath 中,您还可以使用 ${i}风格的路径匹配符来表示from子句中的部分路径。
比如,对于路径root.sg1.d1.v1而言,${1}表示sg1,${2}表示d1,${3}表示v1。
例子:
select s1, s1, s1 into ${1}_t1, ${2}, root.${2}.${1}.t2 from root.sg.d1
这等价于
select s1, s1, s1 into root.sg.d1.sg_t1, root.sg.d1.d1, root.d1.sg.t2 from root.sg.d1
注意,除了下述类型的查询,其余类型的查询(如LAST查询)都不被支持。
原始序列查询
select s1, s1 into t1, t2 from root.sg.d1
时间序列生成函数查询(UDF查询)
select s1, sin(s2) into t1, t2 from root.sg.d1
数学表达式查询
select s1, sin(s2), s1 + s3 into t1, t2, t3 from root.sg.d1
嵌套查询
select -s1, sin(cos(tan(s1 + s2 * s3))) + cos(s3), top_k(s1 + s3, 'k'='1') into t1, t2, t3 from root.sg.d1
Fill 查询
select s1 into fill_s1 from root.sg.d1 where time = 10 fill(float [linear, 1ms, 1ms])
Group By 查询
select count(s1) into group_by_s1 from root.sg.d1 group by ([1, 5), 1ms)
Group By Fill 查询
select last_value(s1) into group_by_fill_s1 from root.sg.d1 group by ([1, 10),1ms) fill (float[PREVIOUS])
注意,除了下述子句,其余查询子句(如 DESC / SOFFSET 等)都不被支持。
支持值过滤
select s1, s1 into t1, t2 from root.sg.d1 where s1 > 0 and s2 < 0
支持时间过滤
select s1, s1 into t1, t2 from root.sg.d1 where time > 0
LIMIT / OFFSET
select s1, s1 into t1, t2 from root.sg.d1 limit 5 offset 1000
select子句中的源序列和into子句中的目标序列数量必须相同select子句不支持带 * 查询into子句中的目标序列不必预先创建(可使用自动创建schema功能)into子句中的目标序列已存在时,您需要保证select子句中的源序列和into子句中的目标序列的数据类型一致into子句中的目标序列必须是互不相同的from子句只允许有一列序列前缀用户必须有下列权限才能正常执行查询写回语句:
select 子句中源序列的 READ_TIMESERIES 权限into 子句中目标序列 INSERT_TIMESERIES 权限更多用户权限相关的内容,请参考权限管理语句。
select_into_insert_tablet_plan_row_limit:执行 select-into 语句时,一个 insert-tablet-plan 中可以处理的最大行数。 默认为 10000。