Resolving a Conflict During an Insert

A database may offer an operation that handles a conflicting unique key by skipping or applying a defined update, depending on syntax and policy.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a record by stable key
  2. Check authority and freshness separately
  3. Choose what a duplicate means for the stored value
  4. Confirm the exact conflict key and updated fields

Trace a record by stable key

An import receives one row for an existing catalogue code. Updating its title under the selected conflict target preserves the record's ID. Primary keys and labels distinguish those fields.

Check authority and freshness separately

Being able to match the existing row does not mean every incoming value should replace it. Compare timestamps or declared precedence where appropriate. See merging settings by priority.[1]

Choose what a duplicate means for the stored value

An import row has external ID A and count seven. If A already holds five, a conflict handler can preserve the earlier row, replace the value or accumulate, according to domain policy. A repeated import differs under those choices. See repeatable request identity.

Existing A=5, incoming A=7
Preserve → 5
Replace → 7
Accumulate → 12, and another repeat can add again

Confirm the exact conflict key and updated fields

Different unique rules can produce different conflicts. Preserve immutable IDs or source facts where required. Test first insert, ordinary conflict, and a repeat after success.

References

  1. PostgreSQL Global Development Group, Concurrency Control ↩