How can I add a timestamp column in hive

2019-01-28 15:15发布

问题:

I have 2 rows like below:

941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894

980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970

I want to insert current time stamp while inserting each row. finally in my hive table row should be like below:

941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894 2014-10-21

980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970 2014-10-22

Is there any way I can insert timestamp directly into hive without using pig script?

回答1:

You can use from_unixtime(unix_timestamp()) while inserting.

For example, suppose you have following tables:

create table t1(c1 String);
create table t2(c1 String, c2 timestamp);

Now you can populate table t2 from t1 with current timestamp:

insert into table t2 select *, from_unixtime(unix_timestamp()) from t1;


标签: hive hiveql