Skip site navigation (1) Skip section navigation (2)

Re: Is there a better way to do this?

From: Osvaldo Rosario Kussama <osvaldo_kussama(at)yahoo(dot)com(dot)br>
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-28 21:59:26
Message-ID: 46D49ABE.7090709@yahoo.com.br (view raw or flat)
Thread:
Lists: pgsql-general
Wei Weng escreveu:
> 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';
> 
> Basically the function takes two parameters, and add the second one (as 
> days) onto the first one (as timestamp without  timezone)
> I don't really like this implementation. Is there a more concise way to 
> do this?
> 


CREATE OR REPLACE FUNCTION AddDays
        (time TIMESTAMP WITHOUT TIME ZONE
        , days INT)
RETURNS TIMESTAMP WITHOUT TIME ZONE AS $$
BEGIN
        RETURN time + days*'1 day'::INTERVAL;
END;
$$ LANGUAGE 'plpgsql';


Osvaldo

In response to

pgsql-general by date

Next:From: Michael GlaesemannDate: 2007-08-28 22:04:17
Subject: Re: Is there a better way to do this?
Previous:From: Michael GlaesemannDate: 2007-08-28 21:58:17
Subject: Re: Is there a better way to do this?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group