2 ms·
> Why don't you know whether or not that tuple is in the relation before you start? Because you've got a unique constraint on some sort of natural key and the
by masklinn 6y ago
> Why don't you know whether or not that tuple is in the relation before you start?
Because you've got a unique constraint on some sort of natural key and the service this data is fed from doesn't have any guarantee it'll only deliver the information once. Or the feed can be replayed in the normal course of operation (e.g. system imports / synchronisations).
Handrolling your upsert creates extra failure modes aplenty and is very tricky to get right, which is why built-in support was ultimately introduced.
> In OLTP, this practice (UPSERT) would cause all sorts of mayhem.
So?