How to implement GOMONTH function - Mailing list pgsql-general

From Andrus
Subject How to implement GOMONTH function
Date
Msg-id f27taj$1njj$1@news.hub.org
Whole thread Raw
Responses Re: How to implement GOMONTH function
Re: How to implement GOMONTH function
List pgsql-general
I need to create function GOMONTH which returns date by given number of
month before or forward using sql or pgsql in 8.1+
For example,
GOMONTH( DATE '20070513', 1 )  should return date '20070613'
GOMONTH( DATE '20070513', -2 )  should return date '20070313'

I tried

CREATE OR REPLACE FUNCTION public.gomonth(date, integer,
        out date) IMMUTABLE AS
$_$
SELECT $1 + $2'months';
$_$ language sql

but got error

ERROR: syntax error at or near "'months'"

How to implement this ?

Andrus.



pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Age function
Next
From: "Alexander Staubo"
Date:
Subject: Re: Age function