Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert multiple rows of data into a hive(0.13.1) table? [duplicate]

Tags:

hive

hiveql

I am looking for an equivalent of bellow query for Hive version 0.13.1.

INSERT INTO TABLE table1 VALUES 
(151, 'cash', 'lunch'), 
(152, 'credit', 'lunch'), 
(153, 'cash', 'dinner');

from this answer it is clear "INSERT.... VALUES" query available after version 0.14.
so what is equivalent of above query for given hive version?

like image 509
John Avatar asked May 05 '17 16:05

John


People also ask

How do you add rows to a Hive table?

Syntax: INSERT INTO TABLE <table_name> VALUES (<add values as per column entity>); Example: To insert data into the table let's create a table with the name student (By default hive uses its default database to store hive tables).

How do I insert the same data in multiple rows?

Insert the same data into multiple cells using Ctrl+Enter Select all the blank cells in a column. Press Ctrl+Enter instead of Enter. All the selected cells will be filled with the data that you typed.

How do I insert multiple rows from one table to another?

INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.

Can you insert into multiple rows?

Yes, instead of inserting each row in a separate INSERT statement, you can actually insert multiple rows in a single statement. To do this, you can list the values for each row separated by commas, following the VALUES clause of the statement.


2 Answers

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

INSERT INTO TABLE table1 
    select 151, 'cash', 'lunch'
    union all
    select 152, 'credit', 'lunch'
    union all
    select 153, 'cash', 'dinner';
like image 173
Jared Avatar answered Jan 01 '23 20:01

Jared


When using the "stack" function, the first number represents the number of rows

INSERT INTO TABLE table1 
select stack
       (
           3
          ,151 ,'cash'   ,'lunch'
          ,152 ,'credit' ,'lunch'
          ,153 ,'cash'   ,'dinner'
       )

or

INSERT INTO TABLE table1 
select inline(array
       (
           struct (151 ,'cash'   ,'lunch')
          ,struct (152 ,'credit' ,'lunch')
          ,struct (153 ,'cash'   ,'dinner')
       ))
like image 40
David דודו Markovitz Avatar answered Jan 01 '23 18:01

David דודו Markovitz