gpt4 book ai didi

type-conversion - Redshift : milliseconds to timestamp

转载 作者:行者123 更新时间:2023-12-03 08:53:34 25 4
gpt4 key购买 nike

假设我们有两个表:

CREATE TABLE IF NOT EXISTS tech_time(
ms_since_epoch BIGINT
);

CREATE TABLE IF NOT EXISTS readable_time(
ts timestamp without time zone,
);

假设 tech_time 有数据,我们想要填充 readed_time

因此,在 Postgres 中,您可以使用 to_timestamp(double precision) 并执行类似的操作

INSERT INTO readable_time(ts)
SELECT DISTINCT to_timestamp(ms_since_epoch::float / 1000) AS ts,
FROM tech_time;

Amazon Redshift 中似乎不存在这样的功能:

function to_timestamp(double precision) does not exist

我的问题是:如何正确填充readed_time,同时损失最少的精度?

最佳答案

我们可以尝试使用 DATEADD 并将 ms_since_epoch 添加到 1970 年 1 月 1 日:

INSERT INTO readable_time (ts)
SELECT DATEADD(ms, ms_since_epoch, 'epoch')
FROM tech_time;

关于type-conversion - Redshift : milliseconds to timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57359832/

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