Slide 7
Slide 7 text
More on inference
“UPSERT” some distributors:
INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo transglobal'),
(6, 'Associated Computing, inc')
ON CONFLICT (did)
DO UPDATE SET dname = EXCLUDED.dname;
●
Must specify which unique index to take update action on.
●
Prefer to do this with inference clause, naming relevant column (or
columns, or expressions, ...).
●
Alternatively, ON CONFLICT can name constraint directly, but
avoid it (Okay for exclusion constraints, but not unique constraints).
●
Very flexible and forgiving. Borrows stuff from CREATE INDEX.
●
Optimizer throws error if it cannot find satisfactory unique index.