Commit 4f9e3306 authored by Tom Lane's avatar Tom Lane

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.
parent 851c83fc
...@@ -10745,6 +10745,14 @@ SELECT NULLIF(value, '(none)') ... ...@@ -10745,6 +10745,14 @@ SELECT NULLIF(value, '(none)') ...
</tbody> </tbody>
</tgroup> </tgroup>
</table> </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>
<sect1 id="functions-aggregate"> <sect1 id="functions-aggregate">
......
...@@ -456,14 +456,9 @@ range_lower(PG_FUNCTION_ARGS) ...@@ -456,14 +456,9 @@ range_lower(PG_FUNCTION_ARGS)
range_deserialize(fcinfo, r1, &lower, &upper, &empty); range_deserialize(fcinfo, r1, &lower, &upper, &empty);
if (empty) /* Return NULL if there's no finite lower bound */
ereport(ERROR, if (empty || lower.infinite)
(errcode(ERRCODE_DATA_EXCEPTION), PG_RETURN_NULL();
errmsg("empty range has no lower bound")));
if (lower.infinite)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("range lower bound is infinite")));
PG_RETURN_DATUM(lower.val); PG_RETURN_DATUM(lower.val);
} }
...@@ -478,14 +473,9 @@ range_upper(PG_FUNCTION_ARGS) ...@@ -478,14 +473,9 @@ range_upper(PG_FUNCTION_ARGS)
range_deserialize(fcinfo, r1, &lower, &upper, &empty); range_deserialize(fcinfo, r1, &lower, &upper, &empty);
if (empty) /* Return NULL if there's no finite upper bound */
ereport(ERROR, if (empty || upper.infinite)
(errcode(ERRCODE_DATA_EXCEPTION), PG_RETURN_NULL();
errmsg("empty range has no upper bound")));
if (upper.infinite)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("range upper bound is infinite")));
PG_RETURN_DATUM(upper.val); PG_RETURN_DATUM(upper.val);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment