diff options
| author | Tom Lane | 2011-11-14 20:34:39 +0000 |
|---|---|---|
| committer | Tom Lane | 2011-11-14 20:34:39 +0000 |
| commit | 4f9e33063cea270166fba12d89fe49876f814398 (patch) | |
| tree | e47b774c64242ae1b1e6c864aec2adabd2cf511d /src | |
| parent | 851c83fc81917c61b063c875fc1bca489dfcc482 (diff) | |
Return NULL instead of throwing error when desired bound is not available.
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/utils/adt/rangetypes.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c index 5c16ca1b19..de9b9a5efb 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); } |
