Re: Interval Question

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Terry Lee Tucker <terry(at)esc1(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Interval Question
Date: 2005-01-11 15:18:03
Message-ID: 20050111071406.V74996@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Tue, 11 Jan 2005, Terry Lee Tucker wrote:

> As you can see, this truck is going to be 2 hours late. The return value I'm
> looking for is the difference between Appt. Interval and Travel Interval, as
> in: return (appt_interval - travel_interval). This value will be stored in a
> column of type interval. I would like for late values to be shown as
> negative. @ -2 hours. I thought that subtracting the larger interval from
> the small would return this but it is always the absolute value. The
> documentation states:
>
> interval values can be written with the following syntax:
>
> [(at)] quantity unit [quantity unit...] [direction]
>
> Where: quantity is a number (possibly signed);
>
> Considering the above statement I believed that I could show this difference
> as a negative value but I haven't been able to figure out how to do it. Can I
> do this, and if so, how?

Well, when I try this with constant values on my 7.4 or 8.0 dev system I
get:

select '3 days 4 hours 17 mins'::interval - '3 days 6 hours 17
mins'::interval;
?column?
-----------
-02:00:00
(1 row)

Can you give a full example?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-01-11 15:19:01 Re: Interval Question
Previous Message Timothy Perrigo 2005-01-11 15:10:48 Re: Interval Question