需求:在创建表的时候有一列类型为array<struct:”id”:string,”l”:string>想要自己造数据向表里insert格式应该怎么写呢?
建表语句如下:
CREATE EXTERNAL TABLE `test.test_imp06`(
`exps` array<struct<id:string,l:string>> COMMENT ‘ceshi')
insert into 的select语句
insert into test.test_imp06
select array(named_struct('id','exp6','l','layer_3'),named_struct('id','exp7','l','layer_6')) as exps
结果:
还有一种写法如下:
select array(struct('id','exp6','l','layer_3'),struct('id','exp7','l','layer_6')) as exps
结果:
两种方法,但是如果使用struct会导致和之前的列名定义的列名无法对应。。最后还是使用name_struct喽