gpt4 book ai didi

postgresql - 将秒数转换为 yyyy-mm-dd hh :mm:ss PostgreSQL

转载 作者:行者123 更新时间:2023-11-29 14:04:50 25 4
gpt4 key购买 nike

我是 PostgreSQL sql 的新手,现在正在处理一个已经存在的数据库。我在表中有一个名为 value 的列,它包含以秒为单位的日期时间戳。所以我正在寻找将这些秒数转换为 Postgres 数据库中的 yyyy-mm-dd hh:mm:ss 的方法。我尝试了以下方法:

SELECT  TO_CHAR('1444646136079 second'::interval, 'yyyy-mm-dd HH24:MI:SS')

1444646136079 is the value I would like to convert But I am getting the following error:

ERROR: interval field value out of range: "1444646136079 second"

最佳答案

interval 不是“时间戳”。

to_timestamp() 函数接受秒作为输入并将其转换为适当的时间戳。我相信你的 1444646136079 实际上是 milli 秒,而不是秒:

select to_char(to_timestamp(1444646136079 / 1000), 'yyyy-mm-dd HH24:MI:SS')

返回:

2015-10-12 12:35:36

关于postgresql - 将秒数转换为 yyyy-mm-dd hh :mm:ss PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com