使用选择和值创建临时表

时间:2019-02-15 21:35:08

标签: hadoop hive temp-tables

我正在尝试在Hive中创建一个临时表,如下所示:

CREATE TEMPORARY TABLE mydb.tmp2 
AS SELECT * FROM (VALUES (0, 'abc')) 
AS T (id , mystr);

但这给了我以下错误:

SemanticException [Error 10296]: Values clause with table constructor not yet supported

还有另一种方法可以通过在同一命令中显式直接提供值来创建临时表吗?

我的最终目标是运行MERGE命令,并将临时表插入到USING命令之后。像这样:

MERGE INTO mydb.mytbl
USING <temporary table>
...

2 个答案:

答案 0 :(得分:0)

配置单元尚不支持values构造函数。您可以使用以下查询来实现:

CREATE TEMPORARY TABLE mydb.tmp2 
AS SELECT 0 as id, 'abc' as mystr;

要进行合并,可以使用以下临时表:

merge into target_table
using ( select * from mydb.tmp2) temp
on temp.id = target_table.id
when matched then update set ...
when not matched then insert values (...);

答案 1 :(得分:0)

使用子查询代替临时表:

MERGE INTO mydb.mytbl t
USING  (SELECT 0 as id, 'abc' as mystr) tmp on tmp.id = t.id
相关问题