From 851c83fc81917c61b063c875fc1bca489dfcc482 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 14 Nov 2011 15:15:53 -0500 Subject: Return FALSE instead of throwing error for comparisons with empty ranges. Change range_before, range_after, range_adjacent to return false rather than throwing an error when one or both input ranges are empty. The original definition is unnecessarily difficult to use, and also can result in undesirable planner failures since the planner could try to compare an empty range to something else while deriving statistical estimates. (This was, in fact, the cause of repeatable regression test failures on buildfarm member jaguar, as well as intermittent failures elsewhere.) Also tweak rangetypes regression test to not drop all the objects it creates, so that the final state of the regression database contains some rangetype objects for pg_dump testing. --- doc/src/sgml/filelist.sgml | 2 +- doc/src/sgml/func.sgml | 73 +++++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 31 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index fb69415f800..7a698e59b3e 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -25,7 +25,7 @@ - + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 7ecf7510435..b9ef827984d 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10460,6 +10460,10 @@ SELECT NULLIF(value, '(none)') ... Range Functions and Operators + + See for an overview of range types. + + shows the operators available for range types. @@ -10556,65 +10560,74 @@ SELECT NULLIF(value, '(none)') ... &< - Does not extend to the right of? + does not extend to the right of int8range(1,20) &< int8range(18,20) t &> - Does not extend to the left of? + does not extend to the left of int8range(7,20) &> int8range(5,10) t -|- - adjacent? + is adjacent to numrange(1.1,2.2) -|- numrange(2.2,3.3) t + - Union + union numrange(5,15) + numrange(10,20) [5,20) - - - - Difference - int8range(5,15) - int8range(10,20) - [5,10) - - * - Intersection + intersection int8range(5,15) * int8range(10,20) [10,15) + + - + difference + int8range(5,15) - int8range(10,20) + [5,10) + + - Range comparisons compare the lower bounds first, and only if - equal, compare the upper bounds. This is generally most useful for - B-tree indexes, rather than being useful comparisons by themselves. + The simple comparison operators <, + >, <=, and + >= compare the lower bounds first, and only if those + are equal, compare the upper bounds. These comparisons are not usually + very useful for ranges, but are provided to allow B-tree indexes to be + constructed on ranges. - See for more details about range operator - behavior. + The left-of/right-of/adjacent operators always return false when an empty + range is involved; that is, an empty range is not considered to be either + before or after any other range. + + + + The union and difference operators will fail if the resulting range would + need to contain two disjoint sub-ranges, as such a range cannot be + represented. shows the functions - available for use with range types. See - for more information and examples of the use of these functions. + available for use with range types. @@ -10658,7 +10671,7 @@ SELECT NULLIF(value, '(none)') ... lower(anyrange) - anyrange + range's element type lower bound of range lower(numrange(1.1,2.2)) 1.1 @@ -10669,7 +10682,7 @@ SELECT NULLIF(value, '(none)') ... upper(anyrange) - anyrange + range's element type upper bound of range upper(numrange(1.1,2.2)) 2.2 @@ -10680,7 +10693,7 @@ SELECT NULLIF(value, '(none)') ... isempty(anyrange) - anyrange + boolean is the range empty? isempty(numrange(1.1,2.2)) false @@ -10691,8 +10704,8 @@ SELECT NULLIF(value, '(none)') ... lower_inc(anyrange) - anyrange - is the lower bound of the range inclusive? + boolean + is the lower bound inclusive? lower_inc(numrange(1.1,2.2)) true @@ -10702,8 +10715,8 @@ SELECT NULLIF(value, '(none)') ... upper_inc(anyrange) - anyrange - is the upper bound of the range inclusive? + boolean + is the upper bound inclusive? upper_inc(numrange(1.1,2.2)) false @@ -10713,8 +10726,8 @@ SELECT NULLIF(value, '(none)') ... lower_inf(anyrange) - anyrange - is the lower bound of the range infinite? + boolean + is the lower bound infinite? lower_inf('(,)'::daterange) true @@ -10724,8 +10737,8 @@ SELECT NULLIF(value, '(none)') ... upper_inf(anyrange) - anyrange - is the upper bound of the range infinite? + boolean + is the upper bound infinite? upper_inf('(,)'::daterange) true -- cgit v1.2.3