Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. The AWS Redshift documentation suggests using DATEADD or ADD_MONTHS, but I'm getting the following error messages.

With DATEADD:

SYNTAX_ERROR: line 2:13: Column 'month' cannot be resolved

With ADD_MONTHS:

SYNTAX_ERROR: line 2:5: Function add_months not registered

This is what my data looks like:

select
    my_date
from
    my_table
limit 3
my_date
2019-03-01
2019-04-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
2019-06-01
2019-07-01
2019-08-01
like image 659
Arturo Sbr Avatar asked Dec 07 '25 15:12

Arturo Sbr


1 Answers

Athena and Redshift are different products. You can find the link to SQL reference in https://docs.aws.amazon.com/athena/latest/ug/ddl-sql-reference.html.

You will need to use date_add('month', 3, my_date) in Athena.

like image 184
ebyhr Avatar answered Dec 10 '25 06:12

ebyhr