In my question about searching for date ranges I tried simplifying the problem and inadvertently posed a different and simpler problem.
Rather than complicate that question with an edit I am going to ask the problem I actually intended.
I have two tables Property and Booking. Bookings have a foreign key to Properties and also start and end date.
The user is searching for free slots and supplies a desired duration in days. They also supply a range of start dates that they are interested in. Therefore a search will be along the lines of: "Find me all properties I want a 3 day slot which starts anytime in May."
Now I can do this by: 1. Running 31 queries for each potential start day 2. Finding all bookings in May, condense them into one array of 31 booleans representing days and loop through looking for slots.
I assume (2) is more efficient in most cases. Is there any better algorithms? Is there a pure SQL solution.
I will be using Django and my dataset is small so I will probably be OK with a 'dumb' approuch but I am curious to know what the best algorithm looks like.