繁体   English   中英

错误:运营商不存在:带时区的时间戳/integer

[英]ERROR: operator does not exist: timestamp with time zone / integer

当我想将时间划分为 integer 时,我收到此错误: ERROR: operator does not exist: timestamp with time zone / integer

postgres中是否有任何function来划分时间到integer?

例如: "2013-11-14 07:46:15+03:30"是带有时区的时间戳,我想要"2013-11-14 07:46:15+03:30" / 2 = "1991-12-08 17:38:07.5+03:30"

我认为问题在于它没有被存储为数字。 如果我明白你在问什么,你想要的是自纪元以来的时间,而不是像01/01/1992这样的时间。

如何在 Postgres 中将日期时间转换为 unix 纪元值? 讨论了将其转换为 epoch 的几种方法,但关键是select extract(epoch from ts) from dataselect date_part('epoch', ts) from data; 其中data是您的表格,而ts是您的时间戳。 然后你应该可以除以 Integer。

我找到了解决这个问题的方法:

SELECT to_timestamp(extract(epoch from DATE)/2) AS date FROM Table

其中 DATE 是您的时区时间戳,而 Table 是您给定的表。 结果的类型是带有时区的时间戳。

暂无
暂无

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

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