Amazon redshift Can';t从postgresql中提取日期

Amazon redshift Can';t从postgresql中提取日期,amazon-redshift,epoch,Amazon Redshift,Epoch,我正在查询数据库(红移),我有一条信息以epoch MS格式存储。设想一张表格,内容如下: Purchase, date 1, 1620140227019 2, 1620140227045 3, 1620140226573 我需要将时间戳转换为可读的日期,但无法使其与to_timestamp()或extract()一起工作。问题首先是值的大小(不支持13位数字)。 我找到的最接近的解决办法是 select to_timestamp(1620140226573/1000, 'SS') 但是结

我正在查询数据库(红移),我有一条信息以epoch MS格式存储。设想一张表格,内容如下:

Purchase, date
1, 1620140227019
2, 1620140227045
3, 1620140226573
我需要将时间戳转换为可读的日期,但无法使其与to_timestamp()或extract()一起工作。问题首先是值的大小(不支持13位数字)。 我找到的最接近的解决办法是

select  to_timestamp(1620140226573/1000, 'SS')
但是结果是
0051-05-0414:57:06
。换句话说,月份、日期和秒是正确的,但年份是错误的。

您可以运行此查询

select to_timestamp(round(1620140227254/1000))

解决方案在文档中:


它不起作用了。然而,我自己也找到了解决方案:选择时区为“epoch”+1620140227019/1000*间隔为“1秒”的时间戳作为转换的时间戳
SELECT timestamp with time zone 'epoch' + 1620140227019/1000 * interval '1 second' AS converted_timestamp
select '1970-01-01'::date + 1620140227019/1000 * interval '1 second'