exclusion-constraint

How to ensure entries with non-overlapping time ranges?

橙三吉。 提交于 2021-02-08 05:16:26
问题 I need to ensure my database only contains entries where two or more of its columns are unique. This can easily be achieved with a UNIQUE constraint over those columns. In my case, I need to forbid duplication only for overlapping time ranges. The table has valid_from and valid_to columns. In some cases one might first need to expire the active entry to by setting valid_to = now , and then inserting a new entry adjusted to valid_from = now and valid_to = infinity . I seem to be able to expire

What does exclusion constraint `EXCLUDE USING gist (c WITH &&)` mean?

只愿长相守 提交于 2020-11-30 07:56:18
问题 From PostgreSQL document Exclusion constraints ensure that if any two rows are compared on the specified columns or expressions using the specified operators, at least one of these operator comparisons will return false or null. The syntax is: CREATE TABLE circles ( c circle, EXCLUDE USING gist (c WITH &&) ); I was wondering what EXCLUDE USING gist (c WITH &&) means? In particular, gist() , c WITH && and EXCLUDE USING . Can it be rewritten in terms of check ? Thanks. 回答1: Whereas a CHECK

Preventing adjacent/overlapping entries with EXCLUDE in PostgreSQL

前提是你 提交于 2019-11-26 18:59:48
I am creating a database which stores arbitrary date/time ranges in PostgreSQL 9.2.4. I want to place a constraint on this database which forces the date/time ranges to be non-overlapping, and non-adjacent (since two adjacent ranges can be expressed as a single continuous range). To do this, I am using an EXCLUDE constraint with a GiST index. Here is the constraint I have currently: ADD CONSTRAINT overlap_exclude EXCLUDE USING GIST ( box( point ( extract(EPOCH FROM "from") - 1, extract(EPOCH FROM "from") - 1 ), point ( extract(EPOCH FROM "to"), extract(EPOCH FROM "to") ) ) WITH && ); The

Preventing adjacent/overlapping entries with EXCLUDE in PostgreSQL

喜欢而已 提交于 2019-11-26 06:44:28
问题 I am creating a database which stores arbitrary date/time ranges in PostgreSQL 9.2.4. I want to place a constraint on this database which forces the date/time ranges to be non-overlapping, and non-adjacent (since two adjacent ranges can be expressed as a single continuous range). To do this, I am using an EXCLUDE constraint with a GiST index. Here is the constraint I have currently: ADD CONSTRAINT overlap_exclude EXCLUDE USING GIST ( box( point ( extract(EPOCH FROM \"from\") - 1, extract