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

时间:2013-12-17 12:40:24

标签: sql postgresql amazon-redshift

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

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

3 个答案:

答案 0 :(得分:5)

使用date_trunc() function最简单,但只有在选择时才会有效:

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

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

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

答案 1 :(得分:0)

检查date_trunc()

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

答案 2 :(得分:-1)

您可以使用以下格式设置日期格式:

select to_char(now(), 'YYYY-MM-DD HH24:MI:00');