0

I have created the following table in hive:

hive> CREATE TABLE IF NOT EXISTS Sensorreading ( recvtime String, nodeid int, sensorid int, systemid int, value float);
OK
Time taken: 3.007 seconds
hive> describe Sensorreading;
OK
recvtime        string
nodeid  int
sensorid        int
systemid        int
value   float
Time taken: 0.381 seconds
hive>

And now I need to insert data in it. I have tried this but it don't work:

INSERT INTO TABLE Sensorreading (recvtime, nodeid, sensorid, systemid, value) VALUES ('2015-05-29 11:10:00',1,1,1,-45.4);

How is the syntax of INSERT? Thanks

Cristina
  • 161
  • 1
  • 1
  • 9

2 Answers2

0

INSERT...VALUES is available starting in Hive 0.14.

Check if your Hive version is 0.14 or later.

sras
  • 818
  • 7
  • 18
  • [cristina.albaladejo@cosmosmaster-gi ~]$ hive version Logging initialized using configuration in jar:file:/usr/local/hive-0.9.0-shark-0.8.0-bin/lib/hive-common-0.9.0-shark-0.8.0.jar!/hive-log4j.properties – Cristina Jun 22 '15 at 09:36
  • It seems you have the version 0.9.0. You can LOAD the files into hive tables or you can INSERT hive tables from queries. More info is at [link](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Writingdataintothefilesystemfromqueries) – sras Jun 22 '15 at 10:01
  • But I would like inserting data through command line. Where can I see an example of this? I need an example as INSERT INTO TABLE name_table VALUES... but to use in hive version 0.9.0. – Cristina Jun 22 '15 at 10:24
  • you cann't insert a single record using `INSERT INTO TABLE name_table VALUES` for the versions prior to 0.14. You can still load the table by other ways discussed in this [link] (http://stackoverflow.com/questions/11053567/inserting-data-into-hive-table) – sras Jun 22 '15 at 11:50
  • I mean that I need an example of that type. I have read the link, I have tried it INSERT INTO TABLE Sensorreading SELECT '22-06-2015', '1', '1', '1', '-123.6' FROM Sensorreading LIMIT 1; but it doesn't work, the table is empty. Could you tell me an specific example? – Cristina Jun 22 '15 at 14:15
0

Insert is possible in hive 0.14. But if you need to insert something than there are two ways for it (manual methods , not any paticular command): 1. First you can load it from text file(changes only done in it i.e including your rows in it) 2. You can copy the part file to local and than do changes and then again revert back to regular path.

Ankit Agrahari
  • 349
  • 9
  • 22