将值插入以逗号分隔的多行
Insert values into multiple rows separated by commas
我有一个 table 一列 id
。现在我想编写一个配置单元查询,它接受逗号分隔的 id
值的输入,拆分它们并逐行插入它们。例如:
输入 - abc,def,ghi
输出-
-----id-----
abc
def
ghi
使用lateral view [outer] + 分解和分裂:
insert into table t2
select
s.id
from table1 t1
lateral view explode (split(t1.id,',')) s as id
演示:
select
s.id
from (select 'abc,def,ghi' as id) t1
lateral view explode (split(t1.id,',')) s as id
结果:
id
abc
def
ghi
split(t1.id,',')
生成一个数组。 explode
- 是一个 table 生成函数 (UDTF),它将数组转换为行。 A lateral view
首先将 UDTF 应用于基础 table 的每一行,然后将生成的输出行连接到输入行。
我有一个 table 一列 id
。现在我想编写一个配置单元查询,它接受逗号分隔的 id
值的输入,拆分它们并逐行插入它们。例如:
输入 - abc,def,ghi
输出-
-----id-----
abc
def
ghi
使用lateral view [outer] + 分解和分裂:
insert into table t2
select
s.id
from table1 t1
lateral view explode (split(t1.id,',')) s as id
演示:
select
s.id
from (select 'abc,def,ghi' as id) t1
lateral view explode (split(t1.id,',')) s as id
结果:
id
abc
def
ghi
split(t1.id,',')
生成一个数组。 explode
- 是一个 table 生成函数 (UDTF),它将数组转换为行。 A lateral view
首先将 UDTF 应用于基础 table 的每一行,然后将生成的输出行连接到输入行。