How to convert a string to timestamp with milliseconds in Hive

前端 未结 5 1784
猫巷女王i
猫巷女王i 2021-02-04 11:27

I have a string \'20141014123456789\' which represents a timestamp with milliseconds that I need to convert to a timestamp in Hive (0.13.0) without losing the milliseconds.

5条回答
  •  灰色年华
    2021-02-04 12:01

    I found a way to avoid the messy concatenation of substrings using the following code:

    select cast(regexp_replace('20141014123456789', 
                               '(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{3})',
                               '$1-$2-$3 $4:$5:$6.$7') as timestamp) 
    

提交回复
热议问题