多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## 语法结构 利用查询语句,将查询结果插入新的表 ~~~ INSERT OVERWRITE [INTO] TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement ~~~ ## 覆盖插入 ~~~ insert overwrite table t_1 partition(city='japan') select id,name,age from stu_partition; ~~~ ## 数据插入本地 要写local ~~~ insert overwrite local directory '/root/hivedata/data' select * from t_1; ~~~ 格式化导入到本地 ~~~ insert overwrite local directory '/root/hivedata/data' row format delimited fields terminated by '\t' select * from t_1; ~~~ ## 数据插入hdfs ~~~ insert overwrite directory '/root/hivedata/data' select * from t_1; ~~~ ## 插入一条数据 ~~~ INSERT INTO TABLE VALUES(XX,YY,ZZ); ~~~ 插入数据到分区 ~~~ insert into table student partition(month='201702') values(1, 'jdxia'); ~~~ ## Multi Inserts多重插入 ~~~ FROM from_statement INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select statement1 [INSERT OVERWRITE TABLE tablename2 [PARTITION ...] Select statement2] ... ~~~ 意思就是里面的多行sql的数据都来自第一个from_statement这个表 ![](https://box.kancloud.cn/65a8ebb9a7ce002836cd8768efebd22c_893x196.png) Dynamic partition inserts动态分区插入: 不会手动指定分区,会根据查询的值来指定分区 partition(写列名) ~~~ INSERT OVERWRITE TABLE tablename PARTITION (partcol1[=val1], partcol2[=val2] ...) select_statement FROM from_statement ~~~ 使用了非严格模式 ~~~ set hive.exec.dynamic.partition.mode=nonstrict ~~~ ![](https://box.kancloud.cn/d3b0f59e45ebb69212cf1c435c15977a_930x154.png) 这边分区我们没有指定,是查询的时候,插入动态插入的