For my database design, I have to options for storing timestamp ranges and preventing overlaps using a gist exclude constraint:
Option 1
create table example (
id bigserial primary key,
kind_id bigint not null,
start timestamp not null,
stop timestamp,
constraint test_start_stop exclude using gist (kind_id with =, tsrange(start, stop) with &&)
);
Option 2
create table example (
id bigserial primary key,
kind_id bigint not null,
start_stop tsrange not null,
constraint test_start_stop exclude using gist (kind_id with =, start_stop with &&)
);
When looking at the documentation, there does not seem to be an implementation for Postgres's tsrange or tstzrange datatypes for the FromSql and ToSql traits in postgres-rs.
These types are supported in sqlx-rs but I'm reluctant to switch because of the work that goes into refactoring.
Are there any drawbacks that I should be aware of when using the first option ?
Addendum: in this thread Erwin Brandstetter cites a line from the manual "Note that exclusion constraints are not supported as arbiters with ON CONFLICT DO UPDATE.", and he mentions that "the ON CONFLICT clause covers conflicts with EXCLUSION constraints, but only for DO NOTHING".