id | contractor_id | is_main (bool)
-------------------------------------------------------
1 | 1 | true
2 | 2 | true
3 | 1 | true
CREATE TABLE example (
id SERIAL PRIMARY KEY,
contractor_id INT NOT NULL,
is_main BOOLEAN NOT NULL,
UNIQUE (contractor_id, is_main)
);
CREATE UNIQUE INDEX CONCURRENTLY contractor_id_main ON table_name (contractor_id, is_main);