Time-based update detection
Some applications need to know database updates for certain time ranges, which might be used for replication of data, auditing scenarios, and so on. The ROW CHANGE TIMESTAMP expression provides this information.
ROW CHANGE TIMESTAMP FOR table-designator
returns
a timestamp representing the time when a row was last changed, expressed
in local time similar to CURRENT TIMESTAMP. For a row that was updated, this
reflects the most recent update to the row. Otherwise, the value corresponds
to the original insert of the row.- The system clock is changed
- The row change timestamp column is GENERATED BY DEFAULT (intended for data propagation only) and a row is provided with an out of sync value.
The table was created using the FOR EACH ROW ON UPDATE AS ROW CHANGE TIMESTAMP clause of the CREATE TABLE command. A ROW CHANGE TIMESTAMP expression returns the value of the column. For this category, the timestamp is precise. The row change timestamp in general when generated by the database is limited by speed of inserts and possible clock manipulations including DST adjustment.
- The table was not created with a row change timestamp column, but one was later added using the FOR EACH ROW ON UPDATE AS ROW CHANGE TIMESTAMP clause of the an ALTER TABLE statement. A ROW CHANGE TIMESTAMP expression returns the value of the column. For this category, the old (pre-alter) rows do not contain the actual timestamp until they are first updated or an offline table reorganization is performed.Note: The timestamp is an approximate time that the actual update occurred in the database, as of the system clock at the time and taking into account the limitation that no timestamps can be repeated within a database/table partition. In practice this is normally a very accurate representation of the time of the update. The row change timestamp, in general, when generated by the database, is limited by speed of inserts and possible clock manipulations including DST adjustments.
Rows that were not updated since the ALTER TABLE statement will return the type default value for the column, which is midnight Jan 01, year 1. Only rows that were updated have a unique timestamp. Rows which have the timestamp materialized via an offline table reorganization return a unique timestamp generated during the reorganization of the table. A REORG TABLE operation with the INPLACE parameter is not sufficient as it does not materialize schema changes.
In either case, the timestamp of a row might also be updated if a redistribution is performed. If the row is moved from one database partition to another during a redistribution, then a new timestamp must be generated which is guaranteed to be unique at the target.