保留毫秒精度的Redshift时间戳转换

时间:2019-02-11 19:26:07

标签: timestamp amazon-redshift

尝试在redshift中将bigint 1549757162511转换为timestamp

  1. select 1549757162511::timestamp;

失败cannot cast type bigint to timestamp without time zone

  1. select timestamp 'epoch' + 1549757162511 / 1000 * interval '1 second';

2019-02-10 00:06:02.000000没有毫秒

  1. 这可行...但是有更好的方法吗?

select dateadd(milliseconds, 1549757162511 % 1000, (timestamp 'epoch' + 1549757162511 / 1000 * interval '1 second'));

2019-02-10 00:06:02.511000

时区为UTC

2 个答案:

答案 0 :(得分:1)

找到了另一种方法。不知道它是否更好,但它是def。清洁工。

(timestamp 'epoch' + 1549757162511::numeric / 1000 * interval '1 second')

答案 1 :(得分:0)

这也可以:

(timestamp 'epoch' + 1549757162511 * interval '0.001 seconds')