Unix Technical Forum

BUG #3260: Subtracting intervals

This is a discussion on BUG #3260: Subtracting intervals within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 3260 Logged by: Dhugael McLean Email address: box@yourtechonline.com PostgreSQL version: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 10:46 AM
Dhugael McLean
 
Posts: n/a
Default BUG #3260: Subtracting intervals


The following bug has been logged online:

Bug reference: 3260
Logged by: Dhugael McLean
Email address: box@yourtechonline.com
PostgreSQL version: 8.1.8
Operating system: FreeBSD
Description: Subtracting intervals
Details:

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.

In case this was some weird casting error, I checked:
select interval '1 day' - interval '55 minutes';
and that failed as well.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 10:46 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #3260: Subtracting intervals

"Dhugael McLean" <box@yourtechonline.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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 10:46 AM
Alvaro Herrera
 
Posts: n/a
Default Re: BUG #3260: Subtracting intervals

Dhugael McLean wrote:

> 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, that answer would be wrong because not all days are 24 hours long
(think DST). You can use justify_hours() if you want to make that
assumption:

alvherre=# select justify_hours('1 day'::interval - '55 minutes'::interval);
justify_hours
---------------
23:05:00
(1 fila)

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:39 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com