diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index b9ef827984d..a7dc05bf382 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -10745,6 +10745,14 @@ SELECT NULLIF(value, '(none)') ...
+
+
+ The lower> and upper> functions return null
+ if the range is empty or the requested bound is infinite.
+ The lower_inc, upper_inc,
+ lower_inf, and upper_inf
+ functions all return false for an empty range.
+
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index 5c16ca1b19e..de9b9a5efb4 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -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);
}