Insert timestamp into Hive
22,215
Solution 1
Can be achieved through current_timestamp()
, but only via select clause. don't even require from
clause in select statment.
insert into team select '101','jim','joe',current_timestamp();
or if your hive version doesn't support leaving from
in select statment
insert into team select '101','jim','joe',current_timestamp() from team limit 1;
Solution 2
If you don't already have a table with at least one row, you can accomplish the desired result as such.
insert into team select '101','jim','joe',current_timestamp() from (select '123') x;
Author by
Frostie_the_snowman
Updated on January 02, 2021Comments
-
Frostie_the_snowman over 3 years
Hi i'm new to Hive and I want to insert the current timestamp into my table along with a row of data.
Here is an example of my team table :
team_id int fname string lname string time timestamp
I have looked at some other examples, How to insert timestamp into a Hive table?, How can I add a timestamp column in hive and can't seem to get it to work. This is what I am trying:
insert into team values('101','jim','joe',from_unixtime(unix_timestamp()));
The error I get is:
FAILED: SemanticException [Error 10293]: Unable to create temp file for insert values Expression of type TOK_FUNCTION not supported in insert/values
If anyone could help, that would be great, many thanks frostie
-
Frostie_the_snowman almost 8 yearsI tried the above and got the following error:
ParseException line 1:65 Failed to recognize predicate '<EOF>'. Failed rule: 'regularBody' in statement
-
sumitya almost 8 yearsAdded one more query to get result.
-
Frostie_the_snowman almost 8 yearsHi @syadav this works but doesn't appear in the table, but if I remove the
limit 1
it works but inputs multiple. Any reason why this would be happening or how I could fix this? -
sumitya almost 8 yearswhat's your hive version? I tested this on
Hive 1.2.1.2.3.4.29-1
it works there. -
Frostie_the_snowman almost 8 yearsusing Hive 1.2.1000.2.4.0.0-169
-
Frostie_the_snowman almost 8 yearsAfter a while of debugging and testing, I have got the following to work correctly:
insert into team select '101','jim','joe',current_timestamp() from team limit 2;
Could you please explain howlimit
works in this command? is it the same as a normal limit on a select query? -
sumitya almost 8 yearsyes it is same as normal query on a table with
limit
.It is almost equivalent toselect * from table
if you don't specify anylimit
you will get all the records from the table. if you want only 1 record thenlimit
is required. -
Frostie_the_snowman almost 8 yearsPerfect, Thanks for all your help
-
Paul Lam over 3 yearsNote that the last query will not insert any values if the table is empty, cause
from ${table}
won't match any records, and the selected values would be omitted.