Fill the blank
Make the key claim race-free: a second request with the same key must fail instead of running.
CREATE TABLE idem (
key text ____,
request_hash text NOT NULL,
response jsonb
);
INSERT INTO idem VALUES ('k1', 'h1', NULL);
INSERT INTO idem VALUES ('k1', 'h1', NULL);Hint 1 of 1
Which constraint rejects duplicates?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A PRIMARY KEY
Correct. The second insert fails with 23505, so only one request does the work.
Only a unique constraint makes the database itself reject the second claim atomically. Two requests racing on a check-then-insert would both see no row and both run.
Why not the others?
- B
NOT NULL. Duplicates would still be allowed. - C
DEFAULT gen_random_uuid(). That makes the server choose keys; the client's key is the point. - D
CHECK (key <> ''). Rejects empty keys but not duplicates.