How to implement GOMONTH function

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: How to implement GOMONTH function
Date: 2007-05-13 20:42:44
Message-ID: f27taj$1njj$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rodrigo De León 2007-05-13 21:26:09 Re: How to implement GOMONTH function
Previous Message Felix Kater 2007-05-13 19:25:37 How access table by tableoid