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

From Tom Lane
Subject Re: Absolute value of intervals
Date
Msg-id 9542.1256655331@sss.pgh.pa.us
Whole thread Raw
In response to Re: Absolute value of intervals  (Sam Mason <sam@samason.me.uk>)
Responses Re: Absolute value of intervals
Re: Absolute value of intervals
Re: Absolute value of intervals
List pgsql-general
Sam Mason <sam@samason.me.uk> writes:
> On Tue, Oct 27, 2009 at 11:27:17AM -0300, Joshua Berry wrote:
>> I couldn't find the operator '@' for intervals

> A simple SQL implementation would look like:

>   CREATE FUNCTION absinterval(interval) RETURNS interval
>     IMMUTABLE LANGUAGE sql AS 'SELECT greatest($1,-$1)';
>   CREATE OPERATOR @ ( PROCEDURE = absinterval, RIGHTARG = interval );

> or is a C version really needed?

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'?

            regards, tom lane

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: Absolute value of intervals
Next
From: Sam Mason
Date:
Subject: Re: Absolute value of intervals