赞
踩
insert into 与 insert overwrite 都可以向hive表中插入数据,但是insert into直接追加到表中数据的尾部,而insert overwrite会重写数据,既先进行删除,再写入
注意:如果存在分区的情况,insert overwrite只重写当前分区数据,不会全部重写
当在hive中同时使用insert into(overwrite) table xx 与with子查询时候,需要将insert放在with as子查询后面(区分:与StarRocks不同,insert放在with as子查询前面)
- WITH TEMP_A AS (
- SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
- ),
- TEMP_B AS (
- SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
- GROUP BY TIME,IOT_ID,NAME
- )
-
- INSERT INTO TABLE TABLE_B
- SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B
注意: 当使用以下语句建表时,需要将create放在with as子查询前面
- DROP TABLE IF EXISTS xx ;
- CREATE TABLE xx AS
- WITH TEMP_A AS (
- SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
- ),
- TEMP_B AS (
- SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
- GROUP BY TIME,IOT_ID,NAME
- )
- SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。