将时间戳插入 table 时,它作为日期插入 - Redshift
When inserting timestamp to a table it inserts as date - Redshift
我有 table1
上面有数据,每一行都有 "period_start"
和 "period_end"
,两列都是 dates
。例如:“2021-06-30”。
我有一个 table2
我用 2 个同名的列创建的,这次它们被保存为 timestamp
(客户想要作为时间戳)。
我 运行 一个将 table1
的结果插入到 table2
但将日期列转换为时间戳的查询。出于某种原因我无法理解,table2
中的结果都是日期而不是时间戳。
正在创建 table2
(删除了其他列):
CREATE TABLE IF NOT EXISTS table2
(
,period_start timestamp ENCODE zstd
,period_end timestamp ENCODE zstd
)
从 table1
插入:
insert into table2 (period_start ,period_end)
select
cast(to_date(period_start,'YYYY-MM-DD HH24:MI:SS') as timestamp),
cast(DATEADD(millisecond, -1,last_day(period_start + 75) + 1) as timestamp)
from table1;
当 运行 相同时 select 我将结果完全视为时间戳,当从 table2
查询时,结果保存为日期。
事实证明查询确实很好(我很高兴)。这是 DBeaver 的一个问题,由于某种原因没有将它们显示为时间戳。我不得不退出并进入程序然后它工作了。
我有 table1
上面有数据,每一行都有 "period_start"
和 "period_end"
,两列都是 dates
。例如:“2021-06-30”。
我有一个 table2
我用 2 个同名的列创建的,这次它们被保存为 timestamp
(客户想要作为时间戳)。
我 运行 一个将 table1
的结果插入到 table2
但将日期列转换为时间戳的查询。出于某种原因我无法理解,table2
中的结果都是日期而不是时间戳。
正在创建 table2
(删除了其他列):
CREATE TABLE IF NOT EXISTS table2
(
,period_start timestamp ENCODE zstd
,period_end timestamp ENCODE zstd
)
从 table1
插入:
insert into table2 (period_start ,period_end)
select
cast(to_date(period_start,'YYYY-MM-DD HH24:MI:SS') as timestamp),
cast(DATEADD(millisecond, -1,last_day(period_start + 75) + 1) as timestamp)
from table1;
当 运行 相同时 select 我将结果完全视为时间戳,当从 table2
查询时,结果保存为日期。
事实证明查询确实很好(我很高兴)。这是 DBeaver 的一个问题,由于某种原因没有将它们显示为时间戳。我不得不退出并进入程序然后它工作了。