sql: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  |
+------------+-----------+----------------------+--+

你可能感兴趣的:(sql)