I have a table with datetime fields
end. And I have a list of (start, end) items. I need to check which items from the list overlap with data in the table.
The current query looks like this:
select br.duration from booking, ( select tstzrange('2016-09-06 03:45:00+00', '2016-09-06 14:45:00+00') as duration union select tstzrange('2016-09-06 14:45:00+00', '2016-09-06 15:45:00+00') as duration -- other items from my list ) as br where tstzrange(start, end) && br.duration
Are there any other ways to do it? Do you think it will work if I have millions rows in the table and will compare them with hundreds items from the list?