Types, Constraints & Database Objects

Boolean, Enum, Domain, and UUID Types

Specialized scalar types can communicate and enforce a domain, but portability, evolution, ordering, generation, and nullability determine whether a native type, reusable domain, lookup relation, or constraint is the durable choice.
  • Boolean is a two-value domain only when NULL is excluded.
  • Enums close a value set into the type definition.
  • A domain packages a base type with reusable constraints.
  • Lookup relations handle evolving reference data.
  • UUIDs decentralize generation but do not prove business identity.
  • Native syntax is not the logical model.
Integrity and portability trade-offs
ChoiceStrengthCost / portability
Boolean + NOT NULLClear binary factSome engines expose integer-like syntax
Native enumCompact closed vocabularyEvolution and ordering are vendor-specific
DomainReusable semantic constraintNot uniformly supported
Lookup relation + FKMetadata and controlled evolutionJoin and lifecycle management
UUIDDistributed key generationLarger indexes; generation/version choices
CREATE DOMAIN positive_quantity AS INTEGER CHECK (VALUE > 0);
CREATE TYPE fulfillment_state AS ENUM ('PENDING', 'PACKED', 'SHIPPED');
CREATE TABLE shipments (
  shipment_id UUID PRIMARY KEY,
  order_id BIGINT NOT NULL REFERENCES orders(order_id),
  quantity positive_quantity NOT NULL,
  state fulfillment_state NOT NULL,
  insured BOOLEAN NOT NULL DEFAULT FALSE
);