简体   繁体   English

Hive SQL 将字符串转换为时间戳而不丢失毫秒

[英]Hive SQL cast string as timestamp without losing the milliseconds

I have string data in the form 2020-10-21 12:49:27.090我的字符串数据格式2020-10-21 12:49:27.090

I want to cast it as a timestamp.我想将其转换为时间戳。 When I do this: select cast(column_name as timestamp) as column_name from table_name当我这样做时: select cast(column_name as timestamp) as column_name from table_name

all of the milliseconds are dropped, like this: 2020-10-21 12:49:27所有毫秒都被丢弃,如下所示: 2020-10-21 12:49:27

I also tried this: select cast(date_format(column_name,'yyyy-MM-dd HH:mm:ss.SSS') as timestamp) as column_name from table_name我也试过这个: select cast(date_format(column_name,'yyyy-MM-dd HH:mm:ss.SSS') as timestamp) as column_name from table_name

and the same problem persists, it drops the milliseconds.并且同样的问题仍然存在,它会减少毫秒。

How do I get it to convert strings to timestamps without losing the milliseconds?如何在不丢失毫秒的情况下将字符串转换为时间戳?

Tested in Hive 2.3.6 on Qubole and on demo.gethue.com , works good:在 Qubole 和 demo.gethue.com 上的Hive 2.3.6 中测试,效果很好:

select cast ('2020-10-21 12:49:27.090' as timestamp), 
       timestamp('2020-10-21 12:49:27.090')

Result:结果:

2020-10-21 12:49:27.09    2020-10-21 12:49:27.09

And this和这个

cast(date_format('2020-10-21 12:49:27.090','yyyy-MM-dd HH:mm:ss.SSS') as timestamp)

also works the same.也一样。

It seems like some problem with your client applpication or Hive version您的客户端应用程序或 Hive 版本似乎有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM