Re: Range Types: << >> -|- ops vs empty range - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: Range Types: << >> -|- ops vs empty range
Date
Msg-id 1297443343.27157.608.camel@jdavis
Whole thread Raw
In response to Re: Range Types: << >> -|- ops vs empty range  ("Erik Rijkers" <er@xs4all.nl>)
Responses Re: Range Types: << >> -|- ops vs empty range
List pgsql-hackers
On Fri, 2011-02-11 at 15:09 +0100, Erik Rijkers wrote:
> On Wed, February 9, 2011 09:35, Jeff Davis wrote:
> > Updated patch.
> >
> 
> The operators  <<  >>  and -|-  have the following behavior with empty ranges:
> 
> testdb=# select '-'::int4range << range(200,300);
> ERROR:  empty range
> testdb=# select '-'::int4range >> range(200,300);
> ERROR:  empty range
> testdb=# select '-'::int4range -|- range(200,300);
> ERROR:  empty range
> 
> I'm not sure if that is deliberate behavior, but they seem
> almost bugs to me.

It's deliberate, but it looks like the error messages could use some
improvement.

> Wouldn't it be better (and more practical) if these would
> return false (or perhaps NULL, for 'unknown') ?

I'm hesitant to return NULL when the inputs are known.

If we were to define these functions for empty ranges, I would think
they would all return true.

"<<" and ">>" ("strictly left of" and "strictly right of", respectively)
could be seen to start out as true and return false if it finds a point
overlapping or on the other side. 

The primary use case for "-|-" (adjacent) is to see if your ranges are
contiguous and non-overlapping. For empty ranges, that seems to be true.

I'm not disagreeing with your interpretation really. I think that
different people will assume different behavior, and so it's more likely
to cause confusion. An error early on will allow them to do something
like: CASE WHEN myrange? THEN myrange -|- range(10,20) ELSE TRUE END
So that they (and anyone who reads their query) can see explicitly
what's happening, without looking in the manual for details.

I'm open to suggestion, however. If we can get a reasonable consensus on
the values these functions should return, I'll change it.

Regards,Jeff Davis



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Add support for logging the current role
Next
From: Stephen Frost
Date:
Subject: Re: Add support for logging the current role