postgresql unique constraint for any integer from two columns (or from array)
You can use exclusion constraint on table along with intarray to quickly perform search of overlapping arrays:
CREATE EXTENSION intarray;CREATE TABLE test ( a int[], EXCLUDE USING gist (a gist__int_ops WITH &&));INSERT INTO test values('{1,2}');INSERT INTO test values('{2,3}');>> ERROR: conflicting key value violates exclusion constraint "test_a_excl">> DETAIL: Key (a)=({2,3}) conflicts with existing key (a)=({1,2}).