Configure SYSTEM_TIME and System Versioning
masterA SYSTEM_TIME period tracks when rows were valid in the system. The columns used for this (start and end) are managed by triggers: the start column is set to transaction_timestamp() and the end column is set to 'infinity'.
Best Practice: Use timestamp with time zone for these columns to avoid issues with TimeZone or Daylight Savings changes.
Setup
Use periods.add_system_time_period to create the columns and the period. You can also exclude specific columns from triggering a new historical row when they are updated.
System Versioning
To enable full system versioning (which maintains a separate history table for all changes), call periods.add_system_versioning after setting up the SYSTEM_TIME period.
-- 1. Create table
CREATE TABLE example (
id bigint PRIMARY KEY,
value text
);
-- 2. Add SYSTEM_TIME period (columns are created automatically)
SELECT periods.add_system_time_period('example', 'row_start', 'row_end');
-- 3. (Optional) Exclude columns from triggering history updates
SELECT periods.set_system_time_period_excluded_columns('example', ARRAY['last_login']);
-- 4. Enable System Versioning to create a history table
SELECT periods.add_system_versioning('example');