5

在 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.

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

4

3 回答 3

7

使用该date_trunc()功能最简单,但这仅在选择时有效:

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

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

INSERT INTO destination_table (
    SELECT date_trunc('minute', date_column), other_columns_here    
    FROM source_table
);
于 2013-12-17T13:49:28.457 回答
0

检查date_trunc()

SELECT date_trunc('minute', TIMESTAMP '2013-12-17 12:27:00');
于 2013-12-17T12:51:44.900 回答
-1

您可以使用以下格式格式化日期:

select to_char(now(), 'YYYY-MM-DD HH24:MI:00');
于 2013-12-17T12:47:36.137 回答