首页 > 解决方案 > 使用 Redshift 转换日期

问题描述

我正在创建一个月末变量,它适用于 postgres,但我必须在 Redshift 中重写它,任何线索为什么它向我显示以下错误?

数据库报告语法错误:Amazon Invalid operation: Interval values with month or year part is not supported 详细信息:---------------------------- -------------------- 错误:不支持带有月份或年份部分的间隔值代码:8001 上下文:i

select
(date_trunc('month', ("Date (id created)" + INTERVAL '1 month'))) as "EoM"
from id

标签: sqldateamazon-redshiftintervals

解决方案


Redshift 使用 dateadd 将间隔应用于时间戳

select date_trunc(month, ( dateadd(month,1,"Date (id created)"))) as "EoM"
from id

请参阅https://docs.aws.amazon.com/redshift/latest/dg/r_DATEADD_function.html


推荐阅读