Re: Subtracting Two Intervals

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Terry Lee Tucker <terry(at)chosen-ones(dot)org>
Cc: Postgres General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Subtracting Two Intervals
Date: 2008-04-07 18:31:13
Message-ID: 200804071831.m37IVDe15407@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Terry Lee Tucker wrote:
> In porting from 7.4.19 to 8.3.1 I have found the following:
>
> 7.4.19:
> mwr=# select interval '1 day 15 hours 30 minutes' - interval '29 hours';
> ?column?
> --------------------
> @ 10 hours 30 mins
> (1 row)
>
> 8.3.1:
> mwr83=# select interval '1 day 15 hours 30 minutes' - interval '29 hours';
> ?column?
> ----------------------------
> @ 1 day -13 hours -30 mins
> (1 row)
>
> Is that right? I mean if you take 1 day (24 hours) and add -13 hours and -30
> minutes, you get 10 hours and 30 minutes, but is it supposed to display that
> way?

We removed assumptions that every day is 24 hours between those
releases. You can use justify_hours() to get the proper result:

test=> select justify_hours(interval '1 day 15 hours 30 minutes' -
interval '29 hours');
justify_hours
---------------
10:30:00
(1 row)

There have been good arguments that justify_hours() behavior should be
the default.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2008-04-07 18:38:58 test ignore
Previous Message David Wilson 2008-04-07 18:27:42 Re: select distinct and index usage