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

 LC--Vincent 发布于 2023-02-09 19:49

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

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

1 个回答
  • 使用该date_trunc()功能最简单,但只有在选择时才能使用:

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

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

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

    2023-02-09 19:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有