Hive:insert into table 与 insert overwrite table 区别

创建测试表,来测试看看测试结果:

create table test(name string,pwd string,createdate string)row format delimited fields terminated by ',';

第一步:使用insert into 插入数据到表中:

insert into test(name,pwd,createdate)values('name1','pwd1','2017-06-20 14:14:09');
insert into test(name,pwd,createdate)values('name1','pwd1','2017-06-20 14:14:09');
insert into test(name,pwd,createdate)values('name2','pwd2','2017-06-20 14:14:09');
insert into test(name,pwd,createdate)values('name2','pwd2','2017-06-20 14:14:09');
0: jdbc:hive2://10.78.152.52:21066/> select * from test;
+------------+-----------+----------------------+--+
| test.name  | test.pwd  |   test.createdate    |
+------------+-----------+----------------------+--+
| name1      | pwd1      | 2017-06-20 14:14:09  |
| name1      | pwd1      | 2017-06-20 14:14:09  |
| name2      | pwd2      | 2017-06-20 14:14:09  |
| name2      | pwd2      | 2017-06-20 14:14:09  |
+------------+-----------+----------------------+--+

第二步:不清理以上插入的记录,直接执行insert overwirte,并查询分析结果:

insert overwrite table test select 'name1' as name,'pwd1' as pwd,'2017-06-20 14:14:09' as createdate;
insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
insert overwrite table test select 'name3' as name,'pwd3' as pwd,'2017-06-20 14:14:09' as createdate;
0: jdbc:hive2://10.78.152.62:21066/> select * from test;
+------------+-----------+----------------------+--+
| test.name  | test.pwd  |   test.createdate    |
+------------+-----------+----------------------+--+
| name3      | pwd3      | 2017-06-20 14:14:09  |
+------------+-----------+----------------------+--+

第三步:不清理上边步骤执行后的结果,接着执行以下sql语句,并查询结果:

insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
0: jdbc:hive2://10.78.152.62:21066/> select * from test;
+------------+-----------+----------------------+--+
| test.name  | test.pwd  |   test.createdate    |
+------------+-----------+----------------------+--+
| name2      | pwd2      | 2017-06-20 14:14:09  |
+------------+-----------+----------------------+--+

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值