From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>, Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: type casting a subselect as an interval |
Date: | 2003-02-21 15:45:20 |
Message-ID: | 20030221074221.A58315-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, 21 Feb 2003, Tom Lane wrote:
> Karel Zak <zakkr(at)zf(dot)jcu(dot)cz> writes:
> > On Fri, Feb 21, 2003 at 07:59:19PM +0900, Jean-Christian Imbeault wrote:
> >> How can I cast the return value of a sub-select as an interval?
> >> select current_timestamp - interval '(select days from T) days'
>
> > You can cast it in the subselect:
>
> > select current_timestamp - (select (days::text || 'd')::interval from T);
>
> A better way of converting numeric values to intervals is to rely on the
> interval-times-float8 operator:
>
> select current_timestamp - (select days from T) * interval '1 day';
>
> This is readable, efficient, and easily adapted to other units (second,
> month, etc)
Since this comes up so often would it make sense to add it to the FAQ
(possibly along with a short description of what interval 'blah' means
since people seem to keep wanting to use it as a cast)
From | Date | Subject | |
---|---|---|---|
Next Message | Henrik Steffen | 2003-02-21 15:46:35 | Re: reindex vs. drop index , create index |
Previous Message | Nigel J. Andrews | 2003-02-21 15:44:10 | Re: Problem with aliasing |