Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3oAh-0001nq-Cj for pgsql-general@arkaria.postgresql.org; Wed, 14 Jul 2021 23:20:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3oAg-0007gy-Co for pgsql-general@arkaria.postgresql.org; Wed, 14 Jul 2021 23:20:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3oAg-0007gq-2x for pgsql-general@lists.postgresql.org; Wed, 14 Jul 2021 23:20:06 +0000 Received: from bumble.maple.relay.mailchannels.net ([23.83.214.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3oAV-0001Xg-4R for pgsql-general@postgresql.org; Wed, 14 Jul 2021 23:20:05 +0000 X-Sender-Id: a2hosting|x-authuser|bench@silentmedia.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 5A2BA361C1A for ; Wed, 14 Jul 2021 23:19:52 +0000 (UTC) Received: from a2ss24.a2hosting.com (100-96-18-103.trex-nlb.outbound.svc.cluster.local [100.96.18.103]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 73D52361B31 for ; Wed, 14 Jul 2021 23:19:51 +0000 (UTC) X-Sender-Id: a2hosting|x-authuser|bench@silentmedia.com Received: from a2ss24.a2hosting.com (a2ss24.a2hosting.com [75.98.175.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.18.103 (trex/6.3.3); Wed, 14 Jul 2021 23:19:52 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|bench@silentmedia.com X-MailChannels-Auth-Id: a2hosting X-Slimy-Lonely: 78cdefe15c96e3fe_1626304792032_1455904919 X-MC-Loop-Signature: 1626304792032:2726872945 X-MC-Ingress-Time: 1626304792031 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=silentmedia.com; s=default; h=Content-Type:MIME-Version:Date:Message-ID: Subject:From:To:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=a/XDF1q72vnxSB5xBVXb+DnaJUh6IpsIEnLYUqh3t/k=; b=eKKYob0QlxMgaejpSNuHJnSXiK 9w6TckFUISeYS48QTbbijd25KBVzrGH25vNXAe0H56dU971T7BMbHQOZvpg3K8k7Qj+mkqEbYyi7P nbBNT4FSG4Re9X04GcQ/IlxUk7yve6mteAtAwO/GEMdtKE2rZH+oK2/GgG2zhb2V7zbbQ6XKBI1eC TagRoVjDpmxosvmlWx4IHDl4qjmL63G1D8uR4LgiT9z3OrQdRAThVjaaOBCEjTlybX/S5lmKuxvzD VJzmhNMD621ufzRZKr22EtsyVPfTBRH0MCJxdrXFvSb+sCfdg1CxHWZ7fforwIa+Wlz06KRb5MR7o U6JmgsNw==; Received: from 97-113-135-130.tukw.qwest.net ([97.113.135.130]:60746 helo=Rolo.local) by a2ss24.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m3oAQ-008ON3-Bn for pgsql-general@postgresql.org; Wed, 14 Jul 2021 19:19:50 -0400 To: pgsql-general From: Ben Chobot Subject: looping over multirange segments? Message-ID: <623b65ef-6bfe-ec35-45c0-341e8f9ab7a8@silentmedia.com> Date: Wed, 14 Jul 2021 16:19:48 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:52.0) Gecko/20100101 PostboxApp/7.0.48 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------300C896B0CECCC8875828171" Content-Language: en-US X-AuthUser: bench@silentmedia.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------300C896B0CECCC8875828171 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I'm really, really liking the multirange types in PG14. Thank you for making them! Unfortunately I am struggling with how to loop over the segments of a multirange. There doesn't seem to be a way to convert them to arrays, and I can't just use plpgsql's FOREACH on one. Am I missing something obvious? It seems like a reasonable thing to want to do. FWIW, my actual end goal is to take something like this: select int8range(1,10)::int8multirange - int8range(4,6)::int8multirange;     ?column? ────────────────  {[1,4),[6,10)} ...and turn it into this: select ???;  int8range │ ?column? ───────────┼──────────  [1,4)     │        0  [6,10)    │        0 --------------300C896B0CECCC8875828171 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit I'm really, really liking the multirange types in PG14. Thank you for making them! Unfortunately I am struggling with how to loop over the segments of a multirange. There doesn't seem to be a way to convert them to arrays, and I can't just use plpgsql's FOREACH on one. Am I missing something obvious? It seems like a reasonable thing to want to do.

FWIW, my actual end goal is to take something like this:

select int8range(1,10)::int8multirange - int8range(4,6)::int8multirange;
    ?column?
────────────────
 {[1,4),[6,10)}

...and turn it into this:

select ???;
 int8range │ ?column?
───────────┼──────────
 [1,4)     │        0
 [6,10)    │        0 --------------300C896B0CECCC8875828171--