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