Re: SELECT and DATE Function question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Aaron Bono" <postgresql(at)aranya(dot)com>
Cc: "Mike C" <smith(dot)not(dot)western(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: SELECT and DATE Function question
Date: 2006-09-11 14:08:24
Message-ID: 22488.1157983704@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"Aaron Bono" <postgresql(at)aranya(dot)com> writes:
> Use:

> select start_date + (cast(number_of_days as text) || ' days')::interval from
> blah

This is a pretty awful way to do it, much better is

select start_date + number_of_days * '1 day'::interval ...

which reduces to basically one multiplication instead of conversion to
text, text string append, parse interval string value (relying on a
couple of undocumented cast abilities).

But the real question here is whether you actually want sub-day
precision in your result. Should the column have been 'date' rather
than 'timestamp' to begin with? If not, what behavior are you expecting
at DST boundaries?

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Marco Bizzarri 2006-09-11 14:49:37 Re: [GENERAL] Problem with lo_export() and lo_import() from remote machine.
Previous Message Purusothaman A 2006-09-11 13:30:00 Re: [GENERAL] Problem with lo_export() and lo_import() from remote machine.