首页 > 解决方案 > Hive - 无法识别选择子句中的输入“插入”

问题描述

假设我已经创建了 table3,并尝试使用以下代码将数据插入其中

WITH table1
AS
(SELECT 1 AS key, 'One' AS value),
table2
AS
(SELECT 1 AS key, 'I' AS value)
INSERT TABLE table3
SELECT t1.key, t1.value, t2.value
  FROM table1 t1 
  JOIN table2 t2
  ON (t1.key = t2.key)

但是,我收到一个错误,因为无法识别 select 子句中的输入“插入”。如果我只是删除插入语句,那么查询运行得很好。

这是语法问题吗?或者我不能使用 with 子句插入?

标签: hivehiveql

解决方案


根据您的需要使用 INTO 或 OVERWRITE:

INSERT INTO TABLE table3  --this will append data, keeping the existing data intact

或者

INSERT OVERWRITE TABLE table3 --will overwrite any existing data

阅读手册:从查询中将数据插入 Hive 表


推荐阅读