Re: Is there a better way to do this? - Mailing list pgsql-general

From Osvaldo Rosario Kussama
Subject Re: Is there a better way to do this?
Date
Msg-id 46D49ABE.7090709@yahoo.com.br
Whole thread Raw
In response to Is there a better way to do this?  (Wei Weng <wweng@kencast.com>)
List 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

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Is there a better way to do this?
Next
From: "Rodrigo De León"
Date:
Subject: Re: Is there a better way to do this?