gpt4 book ai didi

sql - 从 Redshift (PostgreSQL) 中的当前日期中删除秒数

转载 作者:行者123 更新时间:2023-11-29 11:43:24 26 4
gpt4 key购买 nike

在 Amazon Redshift 中,我希望将当前时间戳转换为 0 秒。这是从这个开始:

2013-12-17 12:27:50

为此:

2013-12-17 12:27:00

我尝试了以下方法:

SELECT dateadd(second, -(date_part(second, getdate())), getdate());
ERROR: function pg_catalog.date_add("unknown", double precision, timestamp without time zone) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.

SELECT dateadd(second, -cast(date_part(second, getdate()) as double precision), getdate());
ERROR: function pg_catalog.date_add("unknown", double precision, timestamp without time zone) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.

SELECT getdate() - date_part(second, getdate());
ERROR: operator does not exist: timestamp without time zone - double precision
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.

我可能错过了一个非常简单的方法!请问有人有什么建议吗?

最佳答案

使用 date_trunc() function 最简单,但这只会在选择时起作用:

SELECT date_trunc('minute', TIMESTAMP '2013-12-17 12:27:00');

您可以在将数据加载到 redshift 数据库之前预处理数据,或者使用中间表然后使用 INSERT INTO...SELECT statement :

INSERT INTO destination_table (
SELECT date_trunc('minute', date_column), other_columns_here
FROM source_table
);

关于sql - 从 Redshift (PostgreSQL) 中的当前日期中删除秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20634399/

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