DB2 10.5 for Linux, UNIX, and Windows

Setting the system time for a session

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.

About this task

When you have an application that you want to run against a system-period temporal table to query the state of your business for a number of different dates, you can set the date in a special register. If you need to query your data as of today, as of the end of the last quarter, and as of the same date from last year, it might not be possible to change the application and add AS OF specifications to each SQL statement. This restriction is likely the case when you are using packaged applications. To address such scenarios, you can use the CURRENT TEMPORAL SYSTEM_TIME special register to set the date or timestamp at the session level.

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. .

Important: When the CURRENT TEMPORAL SYSTEM_TIME special register is set to a non-null value, data modification statements like INSERT, UPDATE, and DELETE against system-period temporal tables are blocked. If the special register was set to some time in the past, for example five years ago, then allowing data modification operations might result in changes to your historical data records. Utilities like IMPORT and LOAD are also blocked against system-period temporal tables when the CURRENT TEMPORAL SYSTEM_TIME special register is set to a non-null value.

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.

Procedure

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.

Results

The policy_info table and its associated history table are as follows:
Table 1. Data in the system-period temporal table (policy_info) after the DELETE statement
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
Table 2. History table (hist_policy_info) after delete
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