Skip to content

Instantly share code, notes, and snippets.

@tynor
Last active December 8, 2016 03:21
Show Gist options
  • Save tynor/ff66654b900e7feadbe3ade3ad9317b5 to your computer and use it in GitHub Desktop.
Save tynor/ff66654b900e7feadbe3ade3ad9317b5 to your computer and use it in GitHub Desktop.
CREATE TABLE years (
id uuid PRIMARY KEY,
start_date date NOT NULL,
end_date date NOT NULL,
CHECK (start_date < end_date),
CONSTRAINT overlapping_dates EXCLUDE USING GIST (
box(
point(date_part('epoch', start_date), date_part('epoch', start_date)),
point(date_part('epoch', end_date), date_part('epoch', end_date))
) WITH &&
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment