Generated IDs and Domain Keys

A generated ID can supply durable row identity. A domain key represents a naturally occurring uniqueness rule in the application.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two constraints
  2. Check mutable identifiers
  3. Decide which changes should preserve a row's identity
  4. Define when a domain value is genuinely stable

Trace two constraints

A library can generate a row ID and also require a catalogue code unique within a collection. These prevent different problems. Relational keys discuss candidate identity choices.

Check mutable identifiers

If an external code can change, generated identity can preserve references during replacement. Test losing or changing the domain code under the relevant contract. See stable record identifiers.[1][2]

Decide which changes should preserve a row's identity

A library may assign a generated ID to a book edition and store a catalogue code as a separate unique domain key. If a mistaken catalogue code is corrected, internal references can keep the generated ID. Duplicate domain codes can still be prohibited by their own constraint. See primary keys and display names.

Internal identity: 42
Earlier external code: A17
Corrected external code: A71
References by internal ID still select the same edition

Define when a domain value is genuinely stable

A code managed by another system may be revised or reused. Some domains have durable natural keys. Document who assigns them, and test code correction, collision and incoming references from external systems.

References

  1. PostgreSQL Global Development Group, Data Definition ↩
  2. PostgreSQL Global Development Group, SQL Language Tutorial ↩