Putting the invariant in an exclusion constraint is the right call. For the half-open interval to work you want tstzrange(starts_at, ends_at, '[)') in the constraint. How do you handle temporary holds that expire? I'd expect a partial constraint (WHERE state IN ('held','confirmed')) plus a sweeper, but I'm curious whether you'd rather let the hold lapse by timestamp.
Ahmed Elbashier
Putting the invariant in an exclusion constraint is the right call. For the half-open interval to work you want tstzrange(starts_at, ends_at, '[)') in the constraint. How do you handle temporary holds that expire? I'd expect a partial constraint (WHERE state IN ('held','confirmed')) plus a sweeper, but I'm curious whether you'd rather let the hold lapse by timestamp.