Re: [SQL] Interval subtracting

From: Mark Dilger <pgsql(at)markdilger(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [SQL] Interval subtracting
Date: 2006-03-01 20:39:30
Message-ID: 44060682.9020505@markdilger.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
>
>>I don't think we can accept a change that takes a negative and turns it
>>into a positive and negative.
>
>
> Yeah, I find the patch's changes to the regression results pretty
> disturbing.
>
> Perhaps the correct definition ought to be like "if month part >= 0
> then the reduced day part should be between 0 and 30, otherwise the
> reduced day part should be between 0 and -30". However there are
> still corner cases to worry about. If the original month and day
> parts are of different sign, you might not be able to do such a
> reduction without changing the sign of the month part, consider
> "1 month -95 days". Not clear what to do with this.
>
> I guess I would expect a good result to satisfy one of these three
> cases:
> * month > 0 and 0 <= day < 30
> * month < 0 and -30 < day <= 0
> * month = 0 and -30 < day < 30
> If you believe that then "1 month -95 days" should justify to
> "-2 months -5 days".
>
> regards, tom lane

How would you expect justify_hours to behave? I extrapolate from your rules
above that:

* month > 0 and 0 <= day < 30 and 0 <= hours < 24
* month < 0 and -30 < day <= 0 and -24 < hours <= 0
* month = 0 and -30 < day <= 0 and -24 < hours <= 0
* month = 0 and 0 <= day < 30 and 0 <= hours < 24

Which would mean that '1 month -95 days -12 hours' should justify to "-2 months
-5 days -12 hours" rather than "-2 months -6 days 12 hours", but that '1 month
-15 days -12 hours" would justify to '14 days 12 hours' rather than '15 days -12
hours'.

Is this correct?

mark

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2006-03-01 20:46:12 Re: [SQL] Interval subtracting
Previous Message Scott Marlowe 2006-03-01 20:36:37 Re: [SQL] Interval subtracting

Browse pgsql-patches by date

  From Date Subject
Next Message Mark Dilger 2006-03-01 20:46:12 Re: [SQL] Interval subtracting
Previous Message Scott Marlowe 2006-03-01 20:36:37 Re: [SQL] Interval subtracting

Browse pgsql-sql by date

  From Date Subject
Next Message Simon Kinsella 2006-03-01 20:41:20 Re: Help with trigger that updates a row prior to a potentially aborted deletion?
Previous Message Scott Marlowe 2006-03-01 20:36:37 Re: [SQL] Interval subtracting