How to use a postgres exclude constraint to enforce adjacency

206 Views Asked by At

Let's say I have a table relaxed_schedule, with a contestant_id and a timeslot of type daterange (or any other range, really)

I know how to use an exclude constraint to prevent dateranges from being directly adjacent, like so:

alter table relaxed_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with -|-);

But what I'm looking for is a way to enforce that the dateranges are adjacent, so quite the opposite. Is there something that comes close to the following?

alter table tight_schedule
    add constraint my_exclude_constraint
        exclude using gist ( contestant_id with =, timeslot with !-|-);

Here's an example fiddle: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=172bf2ef20b1289318872ee171374abf

0

There are 0 best solutions below