Re: Split daterange into sub periods

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: hmidi slim <hmidi(dot)slim2(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Split daterange into sub periods
Date: 2018-07-05 14:38:30
Message-ID: CA+bJJbxQ6XRJzOs9Be1G+TAu5fAKC7zd8ZotvegZKiGMC0D9ZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 5, 2018 at 4:16 PM, hmidi slim <hmidi(dot)slim2(at)gmail(dot)com> wrote:
> In fact I'm trying to split a period in sub periods. Following this example
> :
> If I have a period =[2018-01-01, 2018-01-31] and two other periods
> [2018-01-04, 2018-01-06] and [2018-01-08, 2018-01-08].
> If I split the base period '[2018-01-01, 2018-01-31]' by the other two
> periods '[2018-01-04, 2018-01-06]' and '[2018-01-08, 2018-01-08]' I will got
> such a result:
> [2018-01-01, 2018-01-03]
> [2018-01-07, 2018-01-07]
> [2018-01-09, 2018-01-31].

Your example maybe fine to illustrate a definition, but it is totally
inadequate to describe what you want.

You'll, at least, need to refine your question. Something like "I have
a big period and a set of small periods, and want to calculate the set
of subperiods of the big one not covered by the small ones", and also
some conditions ( i.e., can the small periods interesect? are they
completely covered by the big one? can they include the endpoints of
the big one? Can they be empty? Does the result need to be minimal (
in the number of result periods ) ? ).

Even then, this is not trivial and, as said above, you will probably
need a function for it.

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Łukasz Jarych 2018-07-05 14:38:55 Re: Cloning schemas
Previous Message hmidi slim 2018-07-05 14:16:08 Re: Split daterange into sub periods