What's the best way to determine if a year is a leap year in Vertica?
Here is what I was thinking for a function:
Code: Select all
CREATE OR REPLACE FUNCTION is_leapyear(d timestamp)
RETURN BOOLEAN
AS BEGIN
RETURN DECODE(DAY(LAST_DAY(TO_DATE(year(d) || '-02-01', 'YYYY-MM-DD'))), 29, TRUE, FALSE);
END;
Code: Select all
dbadmin=> SELECT sysdate, is_leapyear(sysdate);
sysdate | is_leapyear
----------------------------+-------------
2012-11-14 09:09:14.037244 | t
(1 row)
Thanks!