I'm trying to create a table in PostgreSQL, preventing users from entering an action that takes time during an action that was inserted before.
My objective is to create a hospital schema, and prevent user from adding an operation that takes time during operation that was added before, that's happening in the same room (no overlapping).
Let's say, first, I've added an operation in room 'a1' that takes time between 15:45 and 16:45, Nov 15th then I would like the database to prevent me from adding an operation in room 'a1' that takes time between 16:00 and 17:00, Nov 15th.
Something like (not working):
CONSTRAINT operation_un UNIQUE(room, ???datetime???)