Re: Absolute value of intervals - Mailing list pgsql-general

From Scott Bailey
Subject Re: Absolute value of intervals
Date
Msg-id 4AEA27C7.3070907@comcast.net
Whole thread Raw
In response to Re: Absolute value of intervals  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Absolute value of intervals
List pgsql-general
> I think this came up again recently and somebody pointed out that the
> correct definition isn't as obvious as all that.  The components of
> an interval can have different signs, so should abs('-1 day 1 hour') be
> '1 day -1 hour' or '1 day 1 hour'?  Or what about corner cases like
> '1 day -25 hours'?

I agree with Sam. The absolute value of a negative interval should be
equidistant from zero, not the removal of negative signs. So abs('-1 day
1 hour') should be ('1 day -1 hour'). I don't think your corner case is
any different. So his function and operator should be perfectly valid.

But there is some ambiguity around the length of a month. So INTERVAL '1
month - 30 days' =  INTERVAL '0 days' = INTERVAL '-1 month +30 days'.
But when added to a date, it makes no change for months with 30 days,
adds 1 day for months with 31 days and subtracts 2 days for February.

Scott Bailey

pgsql-general by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: Postgres alpha testing docs and general test packs
Next
From: Jeff Davis
Date:
Subject: Re: Absolute value of intervals