Re: Split daterange into sub periods

2018-07-10 Thread hmidi slim
Based on you example I updated it to get the results that I want: create table hmidi( id serial primary key, product_id integer, d date range) insert into hmidi(product_id, d) values(15, '[2018-11-01, 2018-11-01]'); insert into hmidi(product_id, d) values(15, '[2018-11-03, 2018-11-04]'); Then I u

Re: Split daterange into sub periods

2018-07-06 Thread Alban Hertroys
On 5 July 2018 at 16:16, hmidi slim 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

Re: Split daterange into sub periods

2018-07-05 Thread Adrian Klaver
On 07/05/2018 08:30 AM, Hellmuth Vargas wrote: Hi select ($$[$$|| to_char(min(n.dato),'-MM-DD') || $$,$$ || to_char(max(n.dato),'-MM-DD') || $$]$$)::daterange, daterange(min(n.dato)::date,max(n.dato)::date) from ( select u.dato,anterior,(u.dato-anterior)::interval,sum(case when a

Re: Split daterange into sub periods

2018-07-05 Thread Hellmuth Vargas
Hi select ($$[$$|| to_char(min(n.dato),'-MM-DD') || $$,$$ || to_char(max(n.dato),'-MM-DD') || $$]$$)::daterange, daterange(min(n.dato)::date,max(n.dato)::date) from ( select u.dato,anterior,(u.dato-anterior)::interval,sum(case when anterior is null or (u.dato -anterior)::interval='1 day'::

Re: Split daterange into sub periods

2018-07-05 Thread Andreas Kretschmer
On 05.07.2018 15:49, 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] I try to get such a re

Re: Split daterange into sub periods

2018-07-05 Thread Francisco Olarte
On Thu, Jul 5, 2018 at 4:16 PM, hmidi slim 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-0

Re: Split daterange into sub periods

2018-07-05 Thread hmidi slim
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-0

Split daterange into sub periods

2018-07-05 Thread David G. Johnston
On Thursday, July 5, 2018, hmidi slim wrote: > > I got this error: > > > > *ERROR: result of range difference would not be contiguous* > > Is there any operators to make the split of daterang > > To refine what Adrian said, operators cannot return a setof result so this is basically impossible. T

Re: Split daterange into sub periods

2018-07-05 Thread Adrian Klaver
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? Th

Split daterange into sub periods

2018-07-05 Thread hmidi slim
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] I try to get such a result: 1- [ 2018-01-01, 2018-01-03] 2- [ 2018-