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 1lr7BZ-00083V-Lo for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jun 2021 23:00:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lr7BY-0000yu-Gz for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jun 2021 23:00:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lr7BY-0000ym-0l for pgsql-hackers@lists.postgresql.org; Wed, 09 Jun 2021 23:00:32 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lr7BU-0004Ig-QX for pgsql-hackers@lists.postgresql.org; Wed, 09 Jun 2021 23:00:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rqPy3bVW2KJxnA5ukSe8GxsGx03mcXWMii9S6CaGbIg=; b=DKkVJtxSBAEpIAIP+xkBbd/BYb s20ZPHTo56sjsFFzq8aK/PQw0/uWLex+00ZNArQlgWKl0hA66ypWYVerI1bvBwr9c/RhBn91GpN4B L34fM8n1sOakZimLZC/qX9a6uLj6I9RS3fNQhS9xn3Rhj9EvEHT5Uht0y14euq+oEXcVNcFHmtt6F u4CnAtksRT8xoWEZLIB3/8D6nCPl8UA0Di2pvYMIKngKW8q/RXADtl4sCnunLwGHnwDI2H/uLgnmx u6PQRAvKpjRXkoVgzxz0aZ8yNobGeX/KsD1Z+EHqEr72Hzn3kgt2SYz6AFhGsM5ukg/WTqq3lB0jV U6JiktnQ==; Received: from [2600:380:bd46:9207:1cef:e9a5:35c5:409f] (helo=Ph33rHippo.local) by meldrar.postgresql.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lr7BS-00039A-I9; Wed, 09 Jun 2021 23:00:28 +0000 Subject: Re: unnesting multirange data types To: Alvaro Herrera Cc: Tom Lane , PostgreSQL Hackers References: <202106092056.qitkvnvmpadu@alvherre.pgsql> From: "Jonathan S. Katz" Message-ID: <95432464-1b63-bc84-6f84-e9e9d79f9687@postgresql.org> Date: Wed, 9 Jun 2021 19:00:24 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <202106092056.qitkvnvmpadu@alvherre.pgsql> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cp9DvcLC8bhxg354PntFX6ATu4kyhRamR" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2600:380:bd46:9207:1cef:e9a5:35c5:409f (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --cp9DvcLC8bhxg354PntFX6ATu4kyhRamR Content-Type: multipart/mixed; boundary="dkRl8UmhsiTr0BCZKYhBfgAiFuFNlWYCs"; protected-headers="v1" From: "Jonathan S. Katz" To: Alvaro Herrera Cc: Tom Lane , PostgreSQL Hackers Message-ID: <95432464-1b63-bc84-6f84-e9e9d79f9687@postgresql.org> Subject: Re: unnesting multirange data types References: <202106092056.qitkvnvmpadu@alvherre.pgsql> In-Reply-To: <202106092056.qitkvnvmpadu@alvherre.pgsql> --dkRl8UmhsiTr0BCZKYhBfgAiFuFNlWYCs Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 6/9/21 4:56 PM, Alvaro Herrera wrote: > On 2021-Jun-09, Jonathan S. Katz wrote: >=20 >> I did a couple more tests around this. >> >> As suspected, in PL/pgSQL, there is no way to unpack or iterate over a= >> multirange type. >=20 > Uh. This is disappointing; the need for some way to unnest or unpack a= > multirange was mentioned multiple times in the range_agg thread. I had= > assumed that there was some way to cast the multirange to a range array= , > or somehow convert it, but apparently that doesn't work. Just to be pedantic with examples: SELECT datemultirange( daterange(current_date, current_date + 2), daterange(current_date + 5, current_date + 7))::daterange[]; ERROR: cannot cast type datemultirange to daterange[] LINE 1: ...2), daterange(current_date + 5, current_date + 7))::daterang= =2E.. IF there was an array to cast it into an array, we could then use the array looping construct in PL/pgSQL, but if we could only choose one, I think it'd be more natural/less verbose to have an "unnest". > If the supporting pieces are mostly there, then I opine we should add > something. Agreed. Jonathan --dkRl8UmhsiTr0BCZKYhBfgAiFuFNlWYCs-- --cp9DvcLC8bhxg354PntFX6ATu4kyhRamR Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEE+oS2la8r95ogZD/x8QSccp8cZScFAmDBSAgFAwAAAAAACgkQ8QSccp8cZSfi qhAArWTKYlTp3ICdTKZPaiUwbhvFevNgsP3vT9eDxkghLLAL4cJIc3Q8nywWe2wOFZieFtbU1+Ib sFx2lHTg8JxyZK8QCQ3fRZNsRz8Fy3qkmKgwXFEVN7Bixpj9DdKw33oU1Xk+4VB+4o/HWI46U0GI oLqHq2APU8EAe8Ee+17N+A+Fv7Qa9CVrXtkUYODWmqkmpdUQFcIP8GdJk76dHGk/92bB7rda45kK ZAvF7gk7kQE9SOIwqV6RR7EHzR9gP8ma9hOLQKDQD0IPCoZ1XKLb0iZJ6MU0/WxYsHScgYu9cthB IoLnEqMVxsjjyHvxb0n4h1uaiyT4L7ishhk+oB7naUPb3R+FykSdxWU8q3keHAUUQOJrejQ1W1Hv A8ifMsc18hrnG+8sTqjMq23z5febIPfPKn/ce4hSnLSMue0ZdRrmZljGgbbt1gip9PDWBS7kIUFh 6ytHfhkjbtWA1FRFX/g/bHRCEKNvZ75rdSAcVFXcWmILDVcTJxlgUZY/2NQhEfhvV2IX0jAwrZwr rsHs+PPQMY5CGB6WcCz00krH/24wO1krlrL727o5U6BslQkiWO2gWMoJxYLIUzFipscGaQSk2rkk Ja7y96dT8igG1etouNgJ7GenOETswUXPRlGS2jkDNHH6zLCNLH7zLoKbwB1DiCdvEt0MMumM7TwI OMw= =2i9x -----END PGP SIGNATURE----- --cp9DvcLC8bhxg354PntFX6ATu4kyhRamR--