Querying temporal tables
You can query a temporal table to retrieve data, based on the time criteria that you specify.
About this task
A temporal table that includes a system period (specified by a SYSTEM_TIME clause) and is defined with system-period data versioning is a system-period temporal table. A temporal table that includes an application period (specified by a BUSINESS_PERIOD clause) is an application-period temporal table.
Procedure
To query a temporal table, use one of the following methods:
Example
For example, assume that you have system-period temporal table STT with the column POLICY_ID and you want to retrieve data from one year ago. You can set the CURRENT TEMPORAL SYSTEM_TIME period as follows:
SET CURRENT TEMPORAL SYSTEM_TIME = CURRENT TIMESTAMP – 1 YEAR ;
Then you can issue the SELECT statement:
SELECT * FROM STT
WHERE POLICY_ID = 123 ;
Db2 interprets this SELECT statement as follows:
SELECT * FROM STT
FOR SYSTEM_TIME AS OF CURRENT TEMPORAL SYSTEM_TIME
WHERE POLICY_ID = 123 ;