🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## insert 将查询结果插入Hive表 语法结构 利用查询语句,将查询结果插入新的表 ~~~ 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; ~~~ 把数据插入本地 ~~~ insert overwrite local directory '/root/hivedata/data' select * from t_1; ~~~ 把数据插入hdfs ~~~ insert overwrite directory '/root/hivedata/data' select * from t_1; ~~~ 插入一条数据 ~~~ INSERT INTO TABLE VALUES(XX,YY,ZZ); ~~~ Multi Inserts多重插入: ~~~ FROM from_statement INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select statement1 [INSERT OVERWRITE TABLE tablename2 [PARTITION ...] Select statement2] ... ~~~ ![](https://box.kancloud.cn/6d39a90f608f6d26413fbfeb71ea4529_895x199.png) Dynamic partition inserts动态分区插入: ~~~ 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/b83641c44cedfafb003acfb80fe4b02e_994x167.png) 这边分区我们没有指定,是查询的时候,插入动态插入的