gpt4 book ai didi

sql - 如何在查询 to_timestamp Postgresql 中删除时区

转载 作者:行者123 更新时间:2023-11-29 12:28:34 25 4
gpt4 key购买 nike

我在 Postgresql 中查找,我想删除查询中的 +9 UTC 值。

例如:在to_timestamp列中,我想去掉+09,只保留2016-02-26 00:23:44 值(value)。

这是我的查询:

从 c1.hour 中选择 t,to_timestamp(v),其中 f = 22 和 date_trunc('day',t - '1 hour'::INTERVAL) = '2016-02-26 00:00:00 ' 按 t 排序;

这是我的结果: enter image description here

这是我没有使用 to_timestamp 时的结果: enter image description here

请问我能得到一些帮助吗?

最佳答案

使用to_char()函数将 timestamp 格式化为任何所需的字符串表示形式。示例:

SELECT to_char(now(), 'YYYY-MM-DD HH24:MI:SS')

将返回 2016-02-26 09:37:49(没有时区)

您的查询必须是这样的:

SELECT t, to_char(to_timestamp(v), 'YYYY-MM-DD HH24:MI:SS') 
FROM c1.hour
WHERE
f = 22
AND date_trunc('day',t - '1 hour'::INTERVAL) = '2016-02-26 00:00:00'
ORDER BY t ;

关于sql - 如何在查询 to_timestamp Postgresql 中删除时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35642192/

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