PostgreSQL upper(range) Function

The PostgreSQL upper(range) function returns the upper bound of a given range or multirange.

PostgreSQL upper(range) Syntax

Here is the syntax of the PostgreSQL upper(range) function:

upper(anyrange) -> anyelement
upper(anymultirange) -> anyelement

Parameters

anyrange

Required. A range value.

anymultirange

Required. A multirange value.

Return value

The PostgreSQL upper(range) function returns the upper bound of a given range or multirange.

If the given range is empty, or the upper bound of the range is wireless, the PostgreSQL upper(range) function returns NULL.

PostgreSQL upper(range) Examples

Here are some examples of the PostgreSQL upper(range) function.

To extract the upper bound of [1, 4], use the following statement:

SELECT upper('[1, 4]'::int4range);
 upper
-------
     5

To extract the upper bound of [1, 4), use the following statement:

SELECT upper('[1, 4)'::int4range);
 upper
-------
     4

To extract the upper bound of {[1, 3], [5, 7]}, use the following statement:

SELECT upper('{[1, 3], [5, 7]}'::int4multirange);
 upper
-------
     8

To extract the upper bound of (1, 1), use the following statement:

SELECT upper('(1, 1)'::int4range);
 upper
--------
 <null>