Redshift date function "add_months" not being recognized

0

Redshift is suppose to support a function called "add_months" as seen below:

https://docs.aws.amazon.com/redshift/latest/dg/r_ADD_MONTHS.html

select cast (add_months(1, cast(public.date_column as date)) as date)
 from public.table 
where date_column <= '2023-02-28' limit 10

However, when attempting to execute this function, I get the error message "SQL Error [42883]: ERROR: function add_months(integer, date) does not exist Hint: No function matches the given name and argument types. You may need to add explicit type casts."

I have tested this across different redshift clusters and received the same error. I'm not sure this is a bug?

Adriano
asked a year ago291 views
1 Answer
2
Accepted Answer

Your arguments are in incorrect order. Please pass the integer value as 2nd parameter as shown below:

select cast (add_months(cast(public.date_column as date),1) as date)
 from public.table 
where date_column <= '2023-02-28' limit 10;
profile pictureAWS
EXPERT
answered a year ago
  • Thanks, The error message made me think the function was not found but the parameter order was incorrect.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions