By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
CREATE TABLE
| id | role |
|---|---|
| 1 | c |
| 2 | p |
INSERT 0 2
| captain_id | player_id | captain_role | player_role |
|---|---|---|---|
| 1 | 2 | c | p |
INSERT 0 1
ERROR: insert or update on table "user_user" violates foreign key constraint "fk_captain" DETAIL: Key (captain_id, captain_role)=(2, c) is not present in table "users".
ERROR: insert or update on table "user_user" violates foreign key constraint "fk_player" DETAIL: Key (player_id, player_role)=(1, p) is not present in table "users".
ERROR: insert or update on table "user_user" violates foreign key constraint "fk_captain" DETAIL: Key (captain_id, captain_role)=(2, c) is not present in table "users".