Enforcing adjacent ranges

From: Ben Leslie <benno(at)benno(dot)id(dot)au>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Enforcing adjacent ranges
Date: 2017-12-07 07:42:54
Message-ID: CABZ0LtDKVXS6+9LJWmK-ywcYBJ7tcBKoZVGB79S0Zp5XAntv2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm wondering if there is anyway to enforce that ranges in a table be
adjacent in perhaps a similar way to enforcing that they are
non-overlapping.

Consider a (very simplified table)

CREATE TABLE (
thing_id int,
period tsrange,
EXCLUDE USING gist (thing_id WITH =, period WITH &&),
CHECK (lower_inc(period) and not upper_inc(period))
);

This should (I believe) enforce that all periods for a given thing are
non-overlapping, and that each is lower-inclusive, upper-exclusive ranges.

I'd also like to enforce that all ranges for a given 'thing' are adjacent.

Is that possible?

Thanks,

Ben

Browse pgsql-general by date

  From Date Subject
Next Message Kaliappa, Karthic 2017-12-07 11:29:40 Missing RHEL rpm(pg_catcheck-10) in postgres 10 repo.
Previous Message Jeff Janes 2017-12-07 07:06:42 Re: clean out ./data/base/pgsql_tmp