From: Jonathan S. Katz <jkatz@postgresql.org>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: unnesting multirange data types
Date: Wed, 9 Jun 2021 14:33:56 -0400
Message-ID: <60258efe-bd7e-4886-82e1-196e0cac5433@postgresql.org> (raw)
Hi,
I have been exploring multirange data types using PostgreSQL 14 Beta 1.
Thus far I'm really happy with the user experience, and it has allowed
me to simplify some previously onerous queries!
I do have a question about trying to "unnest" a multirange type into its
individual ranges. For example, I have a query where I want to find the
availability over a given week. This query may look something like:
SELECT datemultirange(daterange(CURRENT_DATE, CURRENT_DATE + 7))
- datemultirange(daterange(CURRENT_DATE + 2, CURRENT_DATE + 4))
as availability;
availability
---------------------------------------------------
{[2021-06-09,2021-06-11),[2021-06-13,2021-06-16)}
(1 row)
I would like to decompose the returned multirange into its individual
ranges, similarly to how I would "unnest" an array:
SELECT * FROM unnest(ARRAY[1,2,3]);
unnest
--------
1
2
3
(3 rows)
So something like:
SELECT unnest('{[2021-06-09,2021-06-11),
[2021-06-13,2021-06-16)}')::datemultirange;
unnest
-------------------------
[2021-06-09,2021-06-11)
[2021-06-13,2021-06-16)
(2 rows)
I looked at the various functions + operators available for the
multirange types in the documentation but could not find anything that
could perform this action.
Does this functionality exist?
Thanks,
Jonathan
Attachments:
OpenPGP_signature (application/pgp-signature, 839B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: jkatz@postgresql.org
Subject: Re: unnesting multirange data types
In-Reply-To: <60258efe-bd7e-4886-82e1-196e0cac5433@postgresql.org>
References: <60258efe-bd7e-4886-82e1-196e0cac5433@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox