How to insert data into a Hive(0.13.1) table?

2019-02-20 17:28发布

I am using Hive version 0.13.1. While trying to insert data into an existing table getting an error while using the below query:

CREATE TABLE table1 (order_num int, payment_type varchar(20), category varchar(20));
INSERT INTO TABLE table1 VALUES (151, 'cash', 'lunch');

ERROR :

ParseException line 1:25 cannot recognize input near 'VALUES' '(' '151' in select clause

While searching, got everyone suggesting above query, but unfortunately it's not working for me. Is it due to different Hive version?
I am getting this ambiguity due to link here
Needs help to insert data to an existing table in Hive.

1条回答
Explosion°爆炸
2楼-- · 2019-02-20 18:13

An insert values statement isn't available in Hive until version .14, so you will need to change your syntax to do a insert select statement.

INSERT INTO TABLE table1 SELECT 151, 'cash', 'lunch';

If you want to insert multiple values then you can union selects

INSERT INTO TABLE table1 
    SELECT 151, 'cash', 'lunch'
    union all
    SELECT 152, 'money', 'dinner';
查看更多
登录 后发表回答