Finding date intersections - Mailing list pgsql-general

From Joe Van Dyk
Subject Finding date intersections
Date
Msg-id CACfv+pKE3srkaSbaWnFO4tBRhDixRb0c=BktdJBmzBMQpEmTeg@mail.gmail.com
Whole thread Raw
Responses Re: Finding date intersections  (John McKown <john.archie.mckown@gmail.com>)
List pgsql-general
I have a table of sales that have possibly overlapping time ranges. I want to find all the timeranges where there's an active sale. How would you do that?

create table sales (
  times tstzrange
);

insert into sales values
  (tstzrange('2014-1-1', '2014-1-2')),
  (tstzrange('2014-1-2', '2014-1-3')),
  (tstzrange('2014-1-2', '2014-1-4')),
  (tstzrange('2014-1-5', '2014-1-6'));

-- want back:
--   tstzrange('2014-1-1', '2014-1-4')
--   tstzrange('2014-1-6', '2014-1-6')

Thanks,
Joe

pgsql-general by date:

Previous
From: John Smith
Date:
Subject: is there a warm standby sync trigger?
Next
From: blackbee045
Date:
Subject: Re: Emulating flexible regex replace