By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TYPE
CREATE TABLE
| id | user_id | status |
|---|---|---|
| 1 | 1 | pending |
| 2 | 2 | in_process |
| 3 | 3 | pending |
| 4 | 3 | completed |
| 5 | 3 | declined |
| 6 | 4 | in_process |
| 7 | 4 | declined |
| 8 | 4 | declined |
| 9 | 4 | completed |
| 10 | 4 | completed |
INSERT 0 10
ERROR: conflicting key value violates exclusion constraint "orders_user_id_excl" DETAIL: Key (user_id)=(1) conflicts with existing key (user_id)=(1).
ERROR: conflicting key value violates exclusion constraint "orders_user_id_excl" DETAIL: Key (user_id)=(1) conflicts with existing key (user_id)=(1).
ERROR: conflicting key value violates exclusion constraint "orders_user_id_excl" DETAIL: Key (user_id)=(2) conflicts with existing key (user_id)=(2).
ERROR: conflicting key value violates exclusion constraint "orders_user_id_excl" DETAIL: Key (user_id)=(2) conflicts with existing key (user_id)=(2).
INSERT 0 6
INSERT 0 6
UPDATE 1
INSERT 0 1