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

From Michael Glaesemann
Subject Re: Is there a better way to do this?
Date
Msg-id F35D61FB-62B6-4320-9501-96138F070EFA@seespotcode.net
Whole thread Raw
In response to Is there a better way to do this?  (Wei Weng <wweng@kencast.com>)
Responses Re: Is there a better way to do this?  (Michael Glaesemann <grzm@seespotcode.net>)
Re: Is there a better way to do this?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Aug 28, 2007, at 15:59 , Wei Weng wrote:

> I don't really like this implementation. Is there a more concise
> way to do this?

create or replace function add_days(timestamp, int)
returns timestamp language sql as $body$
select $1 + $2 * interval '1 day'
$body$;

Note that interval '1 day' is not equal to interval '24 hours'. '1
day' can be 23 or 25 hours across daylight saving time boundaries.

If you mean 24 hours (which you're getting with your 24 * 3600 *
interval '2 second'), you could do

create or replace function add_24_hour_intervals(timestamp, int)
returns timestamp language sql as $body$
select $1 + $2 * interval '24 hours';
$body$;

Do you *really* want timestamp without time zone? It's not like
you're gaining any performance or decreasing storage requirements.
Unless you have a reason for *not* using with time zone, I'd
recommend using timestamp with time zone.

Hope this helps.

Michael Glaesemann
grzm seespotcode net



pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: autovacuum not running
Next
From: Osvaldo Rosario Kussama
Date:
Subject: Re: Is there a better way to do this?