Re: BUG #3260: Subtracting intervals

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dhugael McLean" <box(at)yourtechonline(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3260: Subtracting intervals
Date: 2007-05-03 17:06:23
Message-ID: 6568.1178211983@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Dhugael McLean" <box(at)yourtechonline(dot)com> writes:
> select '1 day'::interval - '55 minutes'::interval;

> ?column?
> -----------------
> 1 day -00:55:00

> If the interval periods are both minutes (hours - hours, days - days, etc),
> this works fine. Days - minutes seems to fail. This should output 23:05:00.

No, this result is correct IMHO. Days and minutes are not interconvertible,
because there are not always 24 hours in a day. As an example using
EST5EDT zone (current US DST law):

regression=# select '2007-03-11'::timestamptz;
timestamptz
------------------------
2007-03-11 00:00:00-05
(1 row)

regression=# select '2007-03-11'::timestamptz + '1 day'::interval;
?column?
------------------------
2007-03-12 00:00:00-04
(1 row)

regression=# select ('2007-03-11'::timestamptz + '1 day'::interval) - '55 minutes'::interval;
?column?
------------------------
2007-03-11 23:05:00-04
(1 row)

regression=# select '2007-03-11'::timestamptz + ('1 day'::interval - '55 minutes'::interval);
?column?
------------------------
2007-03-11 23:05:00-04
(1 row)

regression=# select '2007-03-11'::timestamptz + '23:05:00'::interval;
?column?
------------------------
2007-03-12 00:05:00-04
(1 row)

Postgres gets the fourth case right, but would fail if we adopted
your approach, as shown by the fifth case.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2007-05-03 17:15:46 Re: BUG #3260: Subtracting intervals
Previous Message Dhugael McLean 2007-05-03 16:21:51 BUG #3260: Subtracting intervals