Re: Is there a better way to do this?

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
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:51:41
Message-ID: F35D61FB-62B6-4320-9501-96138F070EFA@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rodrigo De León 2007-08-28 21:54:50 Re: Is there a better way to do this?
Previous Message Alvaro Herrera 2007-08-28 21:46:36 Re: autovacuum not running