Thursday, February 17, 2011

Issue in INTERVAL function

I kept getting an annoying error, while I was trying to use interval function on timestamp field. This ended up to be an bug in teradata's feature. Totally surprised they have not handled this issue. Hopefully they will fix it after my DBA raises a ticket.
Here is the issue:
INTERVAL function does not adjust dates(for leap year or for february) as ADD_MONTHS does. For example, when you execute the following:
SELECT ADD_MONTHS('2011-01-31',1)
You will get an output as 2011-02-28
But, when you use interval function instead:
SELECT CAST('2011-01-31' AS DATE)+ INTERVAL '1' MONTH
You will get an error (2665: Invalid date).

Weird! isn't it? hopefully they fix it sooner and my post will be obsolete.