Setting the system time with the CURRENT TEMPORAL SYSTEM_TIME special register can reduce or eliminate the changes required when running an application against different points in time.
Setting the CURRENT TEMPORAL SYSTEM_TIME special register does not affect regular tables. Only queries on temporal tables with versioning enabled (system-period temporal tables and bitemporal tables) use the time set in the special register. There is also no affect on DDL statements. The special register does not apply to any scans run for referential integrity processing. .
The BIND command contains the SYSTIMESENSITIVE option and is set to YES by default. The SYSTIMESENSITIVE option indicates whether references to system-period temporal tables in static and dynamic SQL statements are affected by the value of the CURRENT TEMPORAL SYSTEM_TIME special register. For more information about the type of objects that CURRENT TEMPORAL SYSTEM_TIME also affects, see CURRENT TEMPORAL SYSTEM_TIME special register. If queries in the application are meant to access only the current version of data, set SYSTIMESENSITIVE to NO to optimize the static queries. For SQL procedures, use the SET_ROUTINE_OPTS procedure to set the bind-like options, called query compiler variables.
When this special register is set to a non-null value, applications that issue a query will return data as of that date or timestamp. The following examples request information from the result tables in the Deleting data from a system-period temporal table topic.
policy_id | coverage | sys_start | sys_end | ts_id |
---|---|---|---|---|
A123 | 12000 | 2010-01-31-22.31.33.495925000000 | 9999-12-30-00.00.00.000000000000 | 2010-01-31-22.31.33.495925000000 |
C567 | 25000 | 2011-02-28-09.10.12.649592000000 | 9999-12-30-00.00.00.000000000000 | 2011-02-28-09.10.12.649592000000 |
policy_id | coverage | sys_start | sys_end | ts_id |
---|---|---|---|---|
C567 | 20000 | 2010-01-31-22.31.33.495925000000 | 2011-02-28-09.10.12.649592000000 | 2010-01-31-22.31.33.495925000000 |
B345 | 18000 | 2010-01-31-22.31.33.495925000000 | 2011-09-01-12.18.22.959254000000 | 2010-01-31-22.31.33.495925000000 |
SELECT policy_id, coverage FROM policy_info
FOR SYSTEM_TIME AS OF TIMESTAMP '2010-05-17-14.45.31.434235000000';
The
SELECT queries both the policy_info and the hist_policy_info tables
and returns:A123, 12000
C567, 20000
B345, 18000
SELECT * FROM view1 FOR SYSTEM_TIME AS OF CURRENT TEMPORAL SYSTEM_TIME;
The
query is then rewritten to:SELECT policy_id, coverage FROM policy_info
FOR SYSTEM_TIME AS OF TIMESTAMP '2011-02-28-09.10.12.649592000000';
The
SELECT queries both the policy_info and the hist_policy_info tables
and returns:A123, 12000
C567, 25000
B345, 18000
The query on view2 involves
a view on a regular table that references a system-period temporal
table, causing an implicit relationship between a regular table and
the special register. The query is implicitly rewritten to: SELECT * FROM view2 FOR SYSTEM_TIME AS OF CURRENT TEMPORAL SYSTEM_TIME;
The
query is then rewritten to:SELECT * FROM regular_table WHERE col1 in (SELECT coverage FROM policy_info
FOR SYSTEM_TIME AS OF TIMESTAMP '2011-02-28-09.10.12.649592000000');
The
SELECT returns rows where col1 values match values
in coverage.