Re: Absolute value of intervals

From: Scott Bailey <artacus(at)comcast(dot)net>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Absolute value of intervals
Date: 2009-10-29 23:39:51
Message-ID: 4AEA27C7.3070907@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2009-10-30 00:43:19 Re: Absolute value of intervals
Previous Message Guillaume Lelarge 2009-10-29 23:27:18 Re: Postgres alpha testing docs and general test packs