[英]Add months to date column in AWS Athena
I have a date column in my_table
and I would like to add three months to it.我在my_table
中有一个日期列,我想在其中添加三个月。 The AWS Redshift documentation suggests using DATEADD
or ADD_MONTHS
, but I'm getting the following error messages. AWS Redshift 文档建议使用DATEADD
或ADD_MONTHS
,但我收到以下错误消息。
With DATEADD
:使用DATEADD
:
SYNTAX_ERROR: line 2:13: Column 'month' cannot be resolved SYNTAX_ERROR:第 2:13 行:无法解析列“月”
With ADD_MONTHS
:使用ADD_MONTHS
:
SYNTAX_ERROR: line 2:5: Function add_months not registered SYNTAX_ERROR:第 2:5 行:Function add_months 未注册
This is what my data looks like:这是我的数据的样子:
select
my_date
from
my_table
limit 3
my_date我的约会 |
---|
2019-03-01 2019-03-01 |
2019-04-01 2019-04-01 |
2019-05-01 2019-05-01 |
I would like to do the following:我想做以下事情:
select
add_months(my_date, 3) as plus3m
from
my_table
limit 3
plus3m plus3m |
---|
2019-06-01 2019-06-01 |
2019-07-01 2019-07-01 |
2019-08-01 2019-08-01 |
Athena and Redshift are different products. Athena 和 Redshift 是不同的产品。 You can find the link to SQL reference in https://docs.aws.amazon.com/athena/latest/ug/ddl-sql-reference.html .您可以在https://docs.aws.amazon.com/athena/latest/ug/ddl-sql-reference.ZFC35FDC70D5FC69D2693EZ中找到 SQL 参考的链接。
You will need to use date_add('month', 3, my_date)
in Athena.您需要在 Athena 中使用date_add('month', 3, my_date)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.