By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
ERROR: conflicting key value violates exclusion constraint "no_different_animals_in_same_cage" DETAIL: Key (cage, animal, int4(is_aggressive))=(1, lion, 1) conflicts with existing key (cage, animal, int4(is_aggressive))=(1, zebra, 0).
TRUNCATE TABLE
CREATE INDEX
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
ERROR: conflicting key value violates exclusion constraint "no_different_animals_in_same_cage" DETAIL: Key (cage, animal, int4(is_aggressive))=(1, lion, 1) conflicts with existing key (cage, animal, int4(is_aggressive))=(1, zebra, 0).
ERROR: duplicate key value violates unique constraint "aggressive_animals_live_alone" DETAIL: Key (cage, is_aggressive)=(2, t) already exists.