当前位置:   article > 正文

Hive insert插入数据与with子查询_hive insert into

hive insert into

1. insert into 与 insert overwrite区别

insert into 与 insert overwrite 都可以向hive表中插入数据,但是insert into直接追加到表中数据的尾部,而insert overwrite会重写数据,既先进行删除,再写入

注意:如果存在分区的情况,insert overwrite只重写当前分区数据,不会全部重写

2. insert 与 with as 子查询一起使用

当在hive中同时使用insert into(overwrite) table xx 与with子查询时候,需要将insert放在with as子查询后面(区分:与StarRocks不同,insert放在with as子查询前面)

  1. WITH TEMP_A AS (
  2. SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
  3. ),
  4. TEMP_B AS (
  5. SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
  6. GROUP BY TIME,IOT_ID,NAME
  7. )
  8. INSERT INTO TABLE TABLE_B
  9. SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B

注意: 当使用以下语句建表时,需要将create放在with as子查询前面

  1. DROP TABLE IF EXISTS xx ;
  2. CREATE TABLE xx AS
  3. WITH TEMP_A AS (
  4. SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
  5. ),
  6. TEMP_B AS (
  7. SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
  8. GROUP BY TIME,IOT_ID,NAME
  9. )
  10. SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/781397
推荐阅读
相关标签
  

闽ICP备14008679号