Checking for schedule conflicts
От | Benjamin Smith |
---|---|
Тема | Checking for schedule conflicts |
Дата | |
Msg-id | 200503120013.15045.lists@benjamindsmith.com обсуждение исходный текст |
Ответы |
Re: Checking for schedule conflicts
Re: Checking for schedule conflicts |
Список | pgsql-general |
Given the tables defined below, what's the easiest way to check for schedule conflicts? So far, the only way I've come up with is to create a huge, multi-dimensional array in PHP, with a data element for every minute of all time taken up by all events, and then check for any of these minutes to be set as I go through all the records. (ugh!) But, how could I do this in the database? But I'd like to see something like "select count(*) FROM events, sched WHERE sched.date=$date AND events.id=sched.events_id ... GROUP BY date, start<finish and finish<start HAVING count(*) >1 " And here's where I get stumped. You can't group by start or end because we need to check if they OVERLAP any other records on the same date. Ideas? // Sometimes, recurring events create table events ( id serial not null primary key, title varchar ); // date=YYYYMMDD, start/end: HH:MM (24-hour) create table sched ( events_id integer not null references events(id), date integer not null, start integer not null, end integer not null ); insert into events (title) VALUES ('Tuesday Pickup'); insert into sched(events_id, date, start, end) VALUES (1, 20050308, 0900, 1300); insert into sched (events_id, date, start, end) VALUES (1, 20050315, 0900, 1300); -- "The best way to predict the future is to invent it." - XEROX PARC slogan, circa 1978
В списке pgsql-general по дате отправления: