在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()
功能最简单,但只有在选择时才能使用:
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 );