Search Postgresql Archives

Finding date intersections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux