sql - 使用 Redshift 转换日期

标签 sql date amazon-redshift intervals

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

数据库报语法错误:Amazon Invalid operation: Interval values with month or year parts are not supported 详情:------------------------ ---------------------- 错误:不支持包含月份或年份部分的区间值代码:8001 上下文:i

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

最佳答案

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

关于sql - 使用 Redshift 转换日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61362026/

相关文章:

sql - Oracle SQL : How do I find the table name given the column names?

javascript - 如何将日期字符串解析为本地日期?

时间间隔不均的组的滚动总和

sql - 3 个月移动平均线 - Redshift SQL

amazon-redshift - 在 dbt 中使用多个数据仓库

sql - Redshift 左外连接忽略空值

sql - 参数化语句能阻止所有SQL注入(inject)吗?

mysql - 如果列值不存在,则不要加入表

mysql - 多列上没有空值的 SQL 连接

java - 在一行中创建没有时区偏移的日期对象