How to ensure entries with non-overlapping time ranges?
问题 I need to ensure my database only contains entries where two or more of its columns are unique. This can easily be achieved with a UNIQUE constraint over those columns. In my case, I need to forbid duplication only for overlapping time ranges. The table has valid_from and valid_to columns. In some cases one might first need to expire the active entry to by setting valid_to = now , and then inserting a new entry adjusted to valid_from = now and valid_to = infinity . I seem to be able to expire