Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4rG-0002Be-0T for pgsql-general@arkaria.postgresql.org; Thu, 05 Jul 2018 14:03:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fb4rE-0004fj-IS for pgsql-general@arkaria.postgresql.org; Thu, 05 Jul 2018 14:03:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4rD-0004fb-NL for pgsql-general@lists.postgresql.org; Thu, 05 Jul 2018 14:03:40 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4r9-0002qx-E4 for pgsql-general@postgresql.org; Thu, 05 Jul 2018 14:03:39 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3806E21CFC; Thu, 5 Jul 2018 10:03:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 05 Jul 2018 10:03:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=DithVcprKBn0jNRAHEgcJskm2bYIR CXOjR5s9hao/Ow=; b=A+gd0xIT06gSsTEeQ0bSJRpzL3JOXOJw4QGA2K6QMghr1 Q5P5nRgPl9YXPsejb8JsqJ10Nz13I6AefBIsklyam2NyOK6+u4CqkVZ29nMKBFGF UZ/MXiW8g9YNUMqoiBXP3DnRjRGR5UIN47SCh8bheLi3eimnSiy/rRGma8qSJJbj RFXG571GGmtMkJ7ZR3SoaCd7ggkuaZxbpbFq+5OBeyHHxh/3L6GHkaTMgu0+FPjj J9TZLCr//pm+SCNAaRb14B/qzzLfGlLMAMn+bRJ4KicmBMvQvJNzg0xvN0224S8E Cf2j7Eqk4NcqV6y7cJMtxlUFb7KfQHRp/dUfmkntQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=DithVc prKBn0jNRAHEgcJskm2bYIRCXOjR5s9hao/Ow=; b=kNt8pWwlwnpYINCu/WNw1K 2XDGmEJyEP4Pc7L7xbmYwSRrA/vt3IXAzPNvGeYH4NeiZJRP8+RtLmalOuWnFXZs hPAk9Dh+aq/XcRPKgVmG9PHSB/KpAqyFPh0PMsRVniXABsKswXQ8k85qscBmgY5R LFykW5oYjjPbb9yKMQrmtS0WsxGPVIWNhsYCpr9KUO+qrvRB0GlxKZ5VxlHsFINy 0HxPz14u1/9hKrvEojLcgvf6SGnzmdI9zMM4Xy4P61JxGO0FENREuevidQqM/dES Y07U/ON3EhkjB/sKbhG3j88NvCp4Ey+sThJt3ME1BL4/hFdIuG6GWpVb1olUjeoA == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.181]) by mail.messagingengine.com (Postfix) with ESMTPA id 8F6CA10336; Thu, 5 Jul 2018 10:03:32 -0400 (EDT) Subject: Re: Split daterange into sub periods To: hmidi slim , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <21b62dd6-fd29-b0da-8b0d-89c04685d97e@aklaver.com> Date: Thu, 5 Jul 2018 07:03:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 07/05/2018 06:49 AM, hmidi slim wrote: > Hi, > I'm looking for splitting a daterange into many subperiods following > this example: > > Base Date: [2018-01-01, 2018-01-31] > overlapped_periods: > 1- [ 2018-01-04, 2018-01-06] > 2- [ 2018-01-09, 2018-01-12] > 3- [ 2018-01-18, 2018-01-19] Overlapping what? They are not overlapping each other. > > I try to get such a result: > 1- [ 2018-01-01, 2018-01-03] > 2- [ 2018-01-07, 2018-01-08] > 3- [ 2018-01-13, 2018-01-17] > 4- [ 2018-01-20, 2018-01-31] Not sure what the above represents. Are you looking for the dates in the range [2018-01-01, 2018-01-31] that are not in the 3 sub-ranges at the top of the post? > > The operator '-' does not support this : > > SELECT daterange('2018-01-01', '2018-01-31', '[]') - > daterange('2018-01-04', '2018-01-06', '[]'); > > I got this error: > > *ERROR: result of range difference would not be contiguous That is expected: https://www.postgresql.org/docs/10/static/functions-range.html "The union and difference operators will fail if the resulting range would need to contain two disjoint sub-ranges, as such a range cannot be represented." > > * > > Is there any operators to make the split of daterange?* > * Not that I know of. > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com