2009-03-25 12:02:55 +07:00
|
|
|
CREATE OR REPLACE FUNCTION add_months (in datetime timestamptz, in months numeric) RETURNS date AS
|
|
|
|
$BODY$
|
|
|
|
declare duration varchar;
|
|
|
|
BEGIN
|
|
|
|
if datetime is null or months is null then
|
|
|
|
return null;
|
|
|
|
end if;
|
|
|
|
duration = months || ' month';
|
|
|
|
return cast(datetime + cast(duration as interval) as date);
|
|
|
|
END;
|
|
|
|
$BODY$
|
2014-05-31 00:11:20 +07:00
|
|
|
LANGUAGE 'plpgsql' IMMUTABLE
|
2009-03-25 12:02:55 +07:00
|
|
|
;
|
2014-05-31 00:11:20 +07:00
|
|
|
|