当前位置:   article > 正文

sql:insert into table 与 insert overwrite table 区别_sql :into table

sql :into table

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

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

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

  1. insert into test(name,pwd,createdate)values('name1','pwd1','2017-06-20 14:14:09');
  2. insert into test(name,pwd,createdate)values('name1','pwd1','2017-06-20 14:14:09');
  3. insert into test(name,pwd,createdate)values('name2','pwd2','2017-06-20 14:14:09');
  4. insert into test(name,pwd,createdate)values('name2','pwd2','2017-06-20 14:14:09');
  5. 0: jdbc:hive2://10.78.152.52:21066/> select * from test;
  6. +------------+-----------+----------------------+--+
  7. | test.name | test.pwd | test.createdate |
  8. +------------+-----------+----------------------+--+
  9. | name1 | pwd1 | 2017-06-20 14:14:09 |
  10. | name1 | pwd1 | 2017-06-20 14:14:09 |
  11. | name2 | pwd2 | 2017-06-20 14:14:09 |
  12. | name2 | pwd2 | 2017-06-20 14:14:09 |
  13. +------------+-----------+----------------------+--

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

  1. insert overwrite table test select 'name1' as name,'pwd1' as pwd,'2017-06-20 14:14:09' as createdate;
  2. insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
  3. insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
  4. insert overwrite table test select 'name3' as name,'pwd3' as pwd,'2017-06-20 14:14:09' as createdate;
  5. 0: jdbc:hive2://10.78.152.62:21066/> select * from test;
  6. +------------+-----------+----------------------+--+
  7. | test.name | test.pwd | test.createdate |
  8. +------------+-----------+----------------------+--+
  9. | name3 | pwd3 | 2017-06-20 14:14:09 |
  10. +------------+-----------+----------------------+--+

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

  1. insert overwrite table test select 'name2' as name,'pwd2' as pwd,'2017-06-20 14:14:09' as createdate;
  2. 0: jdbc:hive2://10.78.152.62:21066/> select * from test;
  3. +------------+-----------+----------------------+--+
  4. | test.name | test.pwd | test.createdate |
  5. +------------+-----------+----------------------+--+
  6. | name2 | pwd2 | 2017-06-20 14:14:09 |
  7. +------------+-----------+----------------------+--+
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/397238
推荐阅读
相关标签
  

闽ICP备14008679号