Range Types: empty ranges

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Range Types: empty ranges
Date: 2011-02-11 18:11:45
Message-ID: 1297447905.27157.660.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Do we want empty ranges?

The philosophy is that they are essentially the "zero" value of any
range type. Like the number zero, it allows closure over operations that
would otherwise return an error.

For instance, the number zero is useful because you can do things like:
f(x) = 5x + 3;
And even if x is zero, the function is still defined, and even produces
a more "real" number like 3. Sure, when you try to divide by zero, you
have a problem, but otherwise it works.

Similarly, "intersection" of ranges is somewhat analogous to
multiplication of numbers.

I have a feeling that there are a lot of applications that might use
intersection in combination with other operators, like overlaps or
contains. If we do allow empty ranges, I think it will be seamless in
most of those situations because "overlaps" and "contains" are
well-defined for empty ranges. But if we don't allow empty ranges, I
suspect that it will cause some user surprise, because depending on the
order of operations an empty range may be created (causing an error) or
not.

The cost, of course, is that not all operations are well-defined for
empty ranges. I think those are mostly operators like those mentioned in
the other thread: ">>" (strictly right of), "<<" (strictly left of), and
"-|-" (adjacent); and perhaps "&>" and "&<". These are probably used a
little less frequently, and should probably not be used in a context
where empty ranges are permitted (if they are, it's likely a mistake and
an error should be thrown).

My feeling is that we should let the operation proceed as far as it is
well-defined, and no further; and I think that means empty ranges should
be allowed.

Thoughts? Do the benefits outweigh the costs?

Regards,
Jeff Davis

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2011-02-11 18:13:27 Re: Debian readline/libedit breakage
Previous Message Josh Berkus 2011-02-11 18:10:13 Re: ALTER EXTENSION UPGRADE, v3