Re: Is there a better way to do this?

From: David Fetter <david(at)fetter(dot)org>
To: Wei Weng <wweng(at)kencast(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is there a better way to do this?
Date: 2007-08-29 16:15:37
Message-ID: 20070829161537.GA31614@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 28, 2007 at 04:59:46PM -0400, Wei Weng wrote:
> Hi all
>
> I want to implement something like the following:
>
> CREATE OR REPLACE FUNCTION AddDays
> (TIMESTAMP WITHOUT TIME ZONE
> , INT)
> RETURNS TIMESTAMP WITHOUT TIME ZONE AS '
> DECLARE
> time ALIAS FOR $1;
> days ALIAS FOR $2;
> BEGIN
> RETURN time+days*24*3600*''1 second''::INTERVAL;
> END;
> ' LANGUAGE 'plpgsql';

This seems like a lot of extra work.

SELECT now() + 5 * INTERVAL '1 day';

does a similar trick, and is quite clear as to what it does :)

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!
Consider donating to PostgreSQL: http://www.postgresql.org/about/donate

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-08-29 16:20:32 Re: ACID (was Re: Reliable and fast ...)
Previous Message Hiroshi Saito 2007-08-29 16:09:25 Re: postgresql connection string to Vb.NET