1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Support for unnest(multirange) and cast multirange as an array of ranges

It has been spotted that multiranges lack of ability to decompose them into
individual ranges.  Subscription and proper expanded object representation
require substantial work, and it's too late for v14.  This commit
provides the implementation of unnest(multirange) and cast multirange as
an array of ranges, which is quite trivial.

unnest(multirange) is defined as a polymorphic procedure.  The catalog
description of the cast underlying procedure is duplicated for each multirange
type because we don't have anyrangearray polymorphic type to use here.

Catversion is bumped.

Reported-by: Jonathan S. Katz
Discussion: https://postgr.es/m/flat/60258efe-bd7e-4886-82e1-196e0cac5433%40postgresql.org
Author: Alexander Korotkov
Reviewed-by: Justin Pryzby, Jonathan S. Katz, Zhihong Yu
This commit is contained in:
Alexander Korotkov
2021-06-15 15:59:20 +03:00
parent 4daa140a2f
commit 29854ee8d1
11 changed files with 354 additions and 9 deletions

View File

@ -19181,6 +19181,29 @@ SELECT NULLIF(value, '(none)') ...
<returnvalue>{[1,2)}</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>unnest</primary>
<secondary>for multirange</secondary>
</indexterm>
<function>unnest</function> ( <type>anymultirange</type> )
<returnvalue>setof anyrange</returnvalue>
</para>
<para>
Expands a multirange into a set of ranges.
The ranges are read out in storage order (ascending).
</para>
<para>
<literal>unnest('{[1,2), [3,4)}'::int4multirange)</literal>
<returnvalue></returnvalue>
<programlisting>
[1,2)
[3,4)
</programlisting>
</para></entry>
</row>
</tbody>
</tgroup>
</table>

View File

@ -266,6 +266,18 @@ SELECT '[4,4)'::int4range;
SELECT '{}'::int4multirange;
SELECT '{[3,7)}'::int4multirange;
SELECT '{[3,7), [8,9)}'::int4multirange;
</programlisting>
</para>
<para>
A multirange can be cast to an array of ranges of the same type.
</para>
<para>
Examples:
<programlisting>
SELECT '{[3,7), [8,9)}'::int4multirange::int4range[];
SELECT '{[1.0,14.0), [20.0,25.0)}'::nummultirange::numrange[];
</programlisting>
</para>