16.10 - Example 2 – ANSI Temporal Syntax - Parallel Transporter

Teradata Parallel Transporter Reference

Product
Parallel Transporter
Release Number
16.10
Published
July 2017
Content Type
Programming Reference
Publication ID
B035-2436-077K
Language
English (United States)

Here is a ANSI Temporal example of the target temporal table definition with a derived period column JOBDURATION as a VALIDTIME column:

CREATE MULTISET TABLE TARGET_EMP_TABLE(
	EMP_ID      INTEGER,
	EMP_NAME    CHAR(30),
	EMP_DEPT    INTEGER,
	JOB_START   DATE NOT NULL,
	JOB_END     DATE NOT NULL,
	PERIOD FOR  JOBDURATION(JOB_START, JOB_END) AS VALIDTIME)
PRIMARY INDEX(EMP_ID);

Here is an example of the Teradata PT schema definition for the sample target ANSI temporal table definition:

DEFINE SCHEMA EMPLOYEE_SCHEMA
DESCRIPTION 'SAMPLE EMPLOYEE SCHEMA'
(
	EMP_ID       INTEGER,
	EMP_NAME     CHAR(30),
	EMP_DEPT     INTEGER,
	JOB_START    INTDATE,
	JOB_END      INTDATE USINGEXTENSION('PERIOD FOR JOBDURATION
							 (JOB_START, JOB_END) AS VALIDTIME')
);

In the sample Teradata PT schema definition, the USINGEXTENSION option is specified for the JOB_END column. The USINGEXTENSION option has a value of 'PERIOD FOR JOBDURATION (JOB_START, JOB_END) AS VALIDTIME'.

The job must specify the DML statement(s) with a temporal qualifier (SEQUENCED, NONSEQUENCED, or CURRENT). Here is a sample DML statement with the SEQUENCED temporal qualifier:

SEQUENCED VALIDTIME INSERT INTO TARGET_EMP_TABLE (:EMP_ID, :EMP_NAME, :EMP_DEPT, :JOB_START, :JOB_END);

The Update operator will build the USING clause and send the USING clause to the Teradata Database. Here is a sample USING clause:

USING EMP_ID(INTEGER),EMP_NAME(CHAR(30)), EMP_DEPT(INTEGER),
	JOB_START(DATE), JOB_END(DATE PERIOD FOR JOBDURATION(JOB_START,
	JOB_END) AS VALIDTIME)
SEQUENCED VALIDTIME INSERT INTO TARGET_EMP_TABLE (:EMP_ID,
	:EMP_NAME, :EMP_DEPT, :JOB_START, :JOB_END);

The Teradata Database needs the USINGEXTENSION value to create the temporal NoPI staging table. During the Acquisition phase, data are populated into the staging table. After the Acquisition phase, the data are merged from the staging table to the temporal target table in the Application phase. After the Application phase, the staging table can be dropped.