Re: How to implement GOMONTH function

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Rodrigo De León <rdeleonp(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to implement GOMONTH function
Date: 2007-05-13 21:35:31
Message-ID: 20070513213531.GB31068@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, May 13, 2007 at 02:26:09PM -0700, Rodrigo De León wrote:
> CREATE OR REPLACE FUNCTION
> PUBLIC.GOMONTH(DATE, INTEGER, OUT DATE) IMMUTABLE AS
> $_$
> SELECT ($1 + ($2 || 'MONTHS')::INTERVAL)::DATE;
> $_$ LANGUAGE SQL

It would probably be better to use:

SELECT ($1 + ($2 * '1 MONTH'::INTERVAL))::DATE;

Less string parsing.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lew 2007-05-13 22:21:15 Re: are foreign keys realized as indexes?
Previous Message Rodrigo De León 2007-05-13 21:26:09 Re: How to implement GOMONTH function