【发布时间】:2020-01-03 05:28:54
【问题描述】:
我在 Hive DB 中有两个时间戳列,以以下格式存储时间戳:
hive> select last_date from xyz limit 2;
OK
2019-08-21 15:11:23.553
2019-08-21 15:11:23.553
[上面默认存储毫秒]
hive> select last_modify_date from xyz limit 2;
OK
2018-04-18 23:32:58
2017-09-22 04:02:32
我需要一个通用的 Hive 选择查询,它将上述时间戳转换为“YYYY-MM-DD HH:mm:ss.SSS”格式,如果存在则保留毫秒值,如果不存在则附加“.000”存在。
到目前为止我所尝试的:
select
last_modify_date,
from_unixtime(unix_timestamp(last_modify_date), "yyyy-MM-dd HH:mm:ss.SSS") as ts
from xyz limit 3;
但是,上述查询对上述两个时间戳列都显示“.000”。
请帮忙
【问题讨论】: