System versioned table: row start/end column has wrong type
ER_VERS_FIELD_WRONG_TYPE (4022) is returned when the row_start or row_end column of a system-versioned table is defined with an incompatible data type. These columns must be TIMESTAMP(6) or BIGINT UNSIGNED.
CREATE TABLE orders ( id INT PRIMARY KEY, row_start INT, -- wrong: must be TIMESTAMP(6) or BIGINT UNSIGNED row_end INT, PERIOD FOR SYSTEM_TIME(row_start, row_end) ) WITH SYSTEM VERSIONING;
expected output
ERROR 4022 (HY000): Sys-ver field 'row_start' has wrong type
Fix
Use TIMESTAMP(6) for the versioning period columns
WHEN When creating or altering a system-versioned table.
CREATE TABLE orders ( id INT PRIMARY KEY, row_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, row_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME(row_start, row_end) ) WITH SYSTEM VERSIONING;
Why this works
TIMESTAMP(6) with GENERATED ALWAYS AS ROW START/END is the canonical definition for system-versioned tables in MariaDB.
✕ Use INT or DATETIME for versioning columns
Only TIMESTAMP(6) and BIGINT UNSIGNED are valid for system-time period columns — any other type causes error 4022.
System versioning (temporal tables) was introduced in MariaDB 10.3. The 4022–4030 range covers system-versioning errors.
MariaDB — System-Versioned Tables
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev