10

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?

Community
  • 1
  • 1
John
  • 1,212
  • 1
  • 16
  • 30

2 Answers2

7

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';
Jared
  • 2,904
  • 6
  • 33
  • 37
3

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')
       ))
David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88