Data Modeling & Schema Design

Temporal Data Modeling

Temporal modeling distinguishes when a fact is true in the business from when the database knew it. Valid time, transaction time, and half-open intervals make corrections, audits, and as-of queries precise instead of overwriting history.
  • Valid time describes the period when a fact applies in the modeled world.
  • Transaction time describes when a version was recorded in the database.
  • Bitemporal data carries both valid-time and transaction-time intervals.
  • Half-open intervals [start, end) compose without boundary overlap.
  • Temporal keys prevent overlapping versions for the same business identity; adding timestamps to an ordinary key does not enforce non-overlap.
  • Current-state, valid-as-of, and known-as-of queries are different APIs and should be named and tested explicitly.

A retroactive product-price correction

Valid-time and transaction-time axes
On February 15 the business-valid start is corrected to February 1; transaction history preserves what was believed before the correction.
Vendor-neutral bitemporal price-history shape
CREATE TABLE product_price_history (
  product_id BIGINT NOT NULL REFERENCES products(product_id),
  valid_from TIMESTAMP NOT NULL,
  valid_to TIMESTAMP NOT NULL,
  recorded_from TIMESTAMP NOT NULL,
  recorded_to TIMESTAMP NOT NULL,
  price DECIMAL(19, 4) NOT NULL CHECK (price >= 0),
  CHECK (valid_from < valid_to),
  CHECK (recorded_from < recorded_to),
  PRIMARY KEY (product_id, valid_from, recorded_from)
);
The primary key makes versions addressable but does not prevent overlapping intervals. Use a database-supported temporal constraint or serialized write procedure to enforce that invariant.
Which question selects which axes?
QuestionValid-time filterTransaction-time filter
Current accepted priceContains nowContains now
Price valid on February 5, using today's corrected knowledgeContains Feb 5Contains now
What the system reported on February 12 for February 5Contains Feb 5Contains Feb 12
Complete auditNo collapseNo collapse