-
+
btree_gist
In addition to the typical btree search operators, btree_gist also
- provides search operators for <> ("not
- equals"). This may be useful in combination with an
- Exclusion Constraint,
- as descibed below.
+ provides search operators for <> (
not
+ equals). This may be useful in combination with an
+ exclusion constraint,
+ as described below.
- Example using an Exclusion
- Constraint to enforce the constraint that a cage at a zoo
+ Use an exclusion
+ constraint to enforce the rule that a cage at a zoo
can contain only one kind of animal:
-=> CREATE TABLE zoo (
+=> CREATE TABLE zoo (
cage INTEGER,
animal TEXT,
- EXCLUDE USING gist (cage WITH =, animal WITH <>)
+ EXCLUDE USING gist (cage WITH =, animal WITH <>)
);
-=> INSERT INTO zoo VALUES(123, 'zebra');
+=> INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
-=> INSERT INTO zoo VALUES(123, 'zebra');
+=> INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
-=> INSERT INTO zoo VALUES(123, 'lion');
+=> INSERT INTO zoo VALUES(123, 'lion');
ERROR: conflicting key value violates exclusion constraint "zoo_cage_animal_excl"
DETAIL: Key (cage, animal)=(123, lion) conflicts with existing key (cage, animal)=(123, zebra).
-=> INSERT INTO zoo VALUES(124, 'lion');
+=> INSERT INTO zoo VALUES(124, 'lion');
INSERT 0 1