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

℡╲_俬逩灬. 提交于 2019-12-01 09:18:14

问题


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:


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';


来源:https://stackoverflow.com/questions/43807372/how-to-insert-data-into-a-hive0-13-1-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!