PostgreSQL range_merge() Function
The PostgreSQL range_merge() function computes the smallest range that includes all specified ranges or the entire multirange.
PostgreSQL range_merge() Syntax
Here is the syntax of the PostgreSQL range_merge() function:
range_merge(anyrange, anyrange) -> anyrange
range_merge(anymultirange) -> anyrange
Parameters
anyrange-
Required. A range value.
anymultirange-
Required. A multirange value.
Return value
The PostgreSQL range_merge() function returns a range, which is the smallest range that contains all the specified ranges or the entire multirange.
PostgreSQL range_merge() Examples
Here are some examples of the PostgreSQL range_merge() function.
Example 1
SELECT range_merge('(1, 3)'::int4range, '(4, 7)'::int4range);
range_merge
-------------
[2,7)Example 2
SELECT range_merge('{(1, 3), (4, 7)}'::int4multirange);
range_merge
-------------
[2,7)