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 1m9zRE-0008Ng-Pt for pgsql-general@arkaria.postgresql.org; Sun, 01 Aug 2021 00:34:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m9zRD-0000J7-Dp for pgsql-general@arkaria.postgresql.org; Sun, 01 Aug 2021 00:34:43 +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 1m9zRC-0000Iy-EH for pgsql-general@lists.postgresql.org; Sun, 01 Aug 2021 00:34:43 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m9zR5-0007o5-JG for pgsql-general@lists.postgresql.org; Sun, 01 Aug 2021 00:34:41 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 686895C0125; Sat, 31 Jul 2021 20:34:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 31 Jul 2021 20:34:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=l 31GmAI74fHwBSQpJsXzMa59LfXB0ZSNqA9Zk1t5910=; b=bA81E9DHtLFZbTHmX 3bUoUpfIMerBf4+TWq/hFaTJ2IVW6sTwB3OSbz7oa6ZeVhFifPYOUO+xk+jJG7dm u+g+pVOixZqdyWv2jyumCnK1zzCGRbEEWUfRBbc6xoIwZHlGG1vyvXB/vboOxUw7 /SlvVTgvQVOpcx8TS9k1FSj1SNLpsxULEd0rynUlyp+EfvGkT6ejX9gPU9vk3YI5 sT6KUgZ1L+mXlW8SjsCyCeA0b1eFFnnbS/+HrjRV+ZPHk51dt8zNvMTQweY4h9Js E2AHrvTyGhknYoRTTdSgOqgOUk7RCc7UdfKHLuAi6nn2W2tLeprLRODhlTGB73vv X6WxA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=l31GmAI74fHwBSQpJsXzMa59LfXB0ZSNqA9Zk1t59 10=; b=OveM1pIawCJTqwlk9P3Lv0EA2rywYZ4hZ3GziyvabXr9SPJhD10WUmCSQ CKv/Y8KEnK4NyHnrIJ9BZSh+R7ZL71b6oyu9RGeDFKLWy6OXN8+gKhWO9J29PwaS GlKZw9yxA7Mxi+ykrCaaitd3ivLWdWc/si3LvAI8e3Vcn9Wfp1c4NpKv9homiC9I l7ilvGWzHmxqcIgo72yUCKFoccTlS1yQKLoZf4Z5SYPNztMr4n8lq8CryhYOHDeE dUpVagC6zxD+t1c00qN/PEbuCfN43GPjMt1SW+W3T0CMkIsCwx+tqiaMn+Y/k0L6 4Nq3YPzDnBfXv7Fe6fzBb+eKdICbA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrheekgddvtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepfffghfegueetgefhledtfefguefhjeehteffieekfeet ueduteffheelieevvdfgnecuffhomhgrihhnpeguvghpvghsiidrtghomhdpphhoshhtgh hrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 31 Jul 2021 20:34:32 -0400 (EDT) Subject: Re: Help with writing a generate_series(tsmultirange, interval) To: =?UTF-8?Q?Fran=c3=a7ois_Beausoleil?= Cc: pgsql-general@lists.postgresql.org References: <7DEBDB22-4E50-4A78-99FE-AF8C03261665@teksol.info> <7aa77027-63c5-21df-181f-0852f9ceadf9@aklaver.com> From: Adrian Klaver Message-ID: <77b75e5a-c765-2161-9588-45958e23a660@aklaver.com> Date: Sat, 31 Jul 2021 17:34:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/31/21 5:16 PM, François Beausoleil wrote: > Hello Adrian, > > Yes, in fact, I wrote the following: > > -------------------------------------------------------------------------------------------------------------------------- > > CREATE FUNCTION generate_series(tstzrange, interval) RETURNS SETOF > timestamp with time zone AS $$ >   SELECT n >   FROM generate_series(lower($1), upper($1), $2) AS t0(n) >   WHERE $1 @> n > $$ LANGUAGE sql immutable; > > CREATE FUNCTION generate_series(tsrange, interval) RETURNS SETOF > timestamp without time zone AS $$ >   SELECT n >   FROM generate_series(lower($1), upper($1), $2) AS t0(n) >   WHERE $1 @> n > $$ LANGUAGE sql immutable; > > That was the easy part. My end goal is to iterate over a tsmultirange: I > would like to get each individual range from a given multi range. > Ideally, I’d like to do that without parsing the textual version of the > multi range. > > While mowing the lawn, I thought that since the syntax of multi ranges > is similar to arrays, maybe I could use unnest(), but sadly, that was > not to be the case: > > # select > unnest('{[2021-08-02,2021-08-04],[2021-08-07,2021-08-09)}'::tsmultirange); > ERROR:  function unnest(tsmultirange) does not exist > LINE 1: select unnest('{[2021-08-02,2021-08-04],[2021-08-07,2021-08-... > > Apparently, PG can accept multi range values, but can’t do much with > them at the time, except to check for inclusion/exclusion. I see your mowing the lawn and raise walking the dog. This rang some bells and then I remembered when in doubt consult depesz: https://www.depesz.com/2021/07/15/how-to-get-list-of-elements-from-multiranges/ https://www.postgresql.org/message-id/20210715121508.GA30348@depesz.com > > Thanks for your time! > François > >>> François >> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com