pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Aaron Bono <postgresql@aranya.com>
Cc: Mike C <smith.not.western@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: SELECT and DATE Function question
Date: Mon, 11 Sep 2006 10:08:24 -0400
Message-ID: <22488.1157983704@sss.pgh.pa.us> (raw)
In-Reply-To: <bf05e51c0609102227u10e4e4c6j7fcdb06690bb9f5b@mail.gmail.com>
References: <bd0eabd0609102153h71fd59ffv6d0ca8a78c27fd9c@mail.gmail.com>
	<bf05e51c0609102227u10e4e4c6j7fcdb06690bb9f5b@mail.gmail.com>

"Aaron Bono" <postgresql@aranya.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



view thread (6+ messages)  latest in thread

Message-ID: <22488.1157983704@sss.pgh.pa.us>
Permalink:  ../22488.1157983704@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22488.1157983704@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, postgresql@aranya.com, smith.not.western@gmail.com
  Subject: Re: SELECT and DATE Function question
  In-Reply-To: <22488.1157983704@sss.pgh.pa.us>
  References: <bd0eabd0609102153h71fd59ffv6d0ca8a78c27fd9c@mail.gmail.com> <bf05e51c0609102227u10e4e4c6j7fcdb06690bb9f5b@mail.gmail.com> <22488.1157983704@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox