从长时间的postgres转换日期

Nir*_*ond 19 sql postgresql time

我想从一个列的纪元时间中选择日期(可读字符串),这些列long在postgres 中有时间(以毫秒为单位)

select *, to_date(time in milli sec) from mytable

怎么做?

Yah*_*hia 30

使用

select *, to_timestamp(time in milli sec / 1000) from mytable
Run Code Online (Sandbox Code Playgroud)

有关参考资料,请参阅http://www.postgresql.org/docs/9.0/static/functions-formatting.html上的postgres文档.

  • 它应该除以浮点数 1000.0,而不是 1000,否则毫秒将被丢弃。 (6认同)

Erw*_*ter 19

SELECT timestamp 'epoch' + time_in_millisec * interval '1 ms'
FROM   mytable;
Run Code Online (Sandbox Code Playgroud)

请参阅此处手册.