]> granicus.if.org Git - postgresql/commitdiff
Return NULL instead of throwing error when desired bound is not available.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 14 Nov 2011 20:34:39 +0000 (15:34 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 14 Nov 2011 20:34:39 +0000 (15:34 -0500)
Change range_lower and range_upper to return NULL rather than throwing an
error when the input range is empty or the relevant bound is infinite.  Per
discussion, throwing an error seems likely to be unduly hard to work with.
Also, this is more consistent with the behavior of the constructors, which
treat NULL as meaning an infinite bound.

doc/src/sgml/func.sgml
src/backend/utils/adt/rangetypes.c

index b9ef827984d31bb6708afb2606b72a9b6d8d3876..a7dc05bf3822a209adad08180605e832497d4c46 100644 (file)
@@ -10745,6 +10745,14 @@ SELECT NULLIF(value, '(none)') ...
       </tbody>
      </tgroup>
     </table>
+
+  <para>
+   The <function>lower</> and  <function>upper</> functions return null
+   if the range is empty or the requested bound is infinite.
+   The <function>lower_inc</function>, <function>upper_inc</function>,
+   <function>lower_inf</function>, and <function>upper_inf</function>
+   functions all return false for an empty range.
+  </para>
   </sect1>
 
  <sect1 id="functions-aggregate">
index 5c16ca1b19e9d9b7b3c64182317902bff4387244..de9b9a5efb4759aba35349435181e4ad8674fda9 100644 (file)
@@ -456,14 +456,9 @@ range_lower(PG_FUNCTION_ARGS)
 
        range_deserialize(fcinfo, r1, &lower, &upper, &empty);
 
-       if (empty)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DATA_EXCEPTION),
-                                errmsg("empty range has no lower bound")));
-       if (lower.infinite)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DATA_EXCEPTION),
-                                errmsg("range lower bound is infinite")));
+       /* Return NULL if there's no finite lower bound */
+       if (empty || lower.infinite)
+               PG_RETURN_NULL();
 
        PG_RETURN_DATUM(lower.val);
 }
@@ -478,14 +473,9 @@ range_upper(PG_FUNCTION_ARGS)
 
        range_deserialize(fcinfo, r1, &lower, &upper, &empty);
 
-       if (empty)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DATA_EXCEPTION),
-                                errmsg("empty range has no upper bound")));
-       if (upper.infinite)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DATA_EXCEPTION),
-                                errmsg("range upper bound is infinite")));
+       /* Return NULL if there's no finite upper bound */
+       if (empty || upper.infinite)
+               PG_RETURN_NULL();
 
        PG_RETURN_DATUM(upper.val);
 }