mariadbtemporal-tablesmariadb-10.4

MariaDB - Inserting historical data into a system versioned (temporal) table


I have some tables in MariaDB that I have been tracking the changes for by using a separate "changelog" table that updates every time a record is updated. However I have recently learned about temporal data tables in MariaDB and I would like to switch to that method as it is a much more elegant method of tracking changes. I'm wondering, however, if there is a way to transfer over my "changelog" table to the newly system versioned tables.

So I was hoping I could insert new rows somehow with the specified values for the table and also specify the row_end and row_start columns and also have that not trigger the table to create another historical row... is this possible? I tried just doing a a "insert into (id, row_start, row_end, etc) values(x, y, z)" but that results in an unknown column "row_start" error.


Solution

  • Old question, but starting with 10.11 MariaDB allows direct insertion of historical data using a command line option or setting.

    https://mariadb.com/kb/en/system-versioned-tables/#system_versioning_insert_history

    system_versioning_insert_history
    Description: Allows direct inserts into ROW_START and ROW_END columns if secure_timestamp allows changing timestamp.
    Commandline: --system-versioning-insert-history[={0|1}]
    Scope: Global, Session
    Dynamic: Yes
    Type: Boolean
    Default Value: OFF
    Introduced: MariaDB 10.11.0