Temporal tables contain
rows that can be current, history, or future in the valid-time dimension.
In the transaction-time dimension, rows can be open or closed. Temporal
qualifiers specify what data is needed. As a
LIBNAME and a
data set option,
TEMPORAL_QUALIFIER= lets you qualify queries in the valid-time or
transaction-time dimension. For example, to fetch rows that are valid
as of
'2009-01-01'
in a table, you must specify
TEMPORAL_QUALIFIER='VALIDTIME
AS OF DATE '2009-01-01' '
as a LIBNAME or a data set
option when you query temporal tables.
The option that you
specify for TEMPORAL_QUALIFIER= is free-form text. Here are some examples.
TEMPORAL_QUALIFIER='CURRENT VALIDTIME'
TEMPORAL_QUALIFIER='VALIDTIME AS OF DATE '2009-01-01' '
TEMPORAL_QUALIFIER='NONSEQUENCED VALIDTIME'
TEMPORAL_QUALIFIER=' SEQUENCED VALIDTIME'
TEMPORAL_QUALIFIER='NONSEQUENCED VALIDTIME PERIOD '(2007-01-01, 2008-03-01)''
TEMPORAL_QUALIFIER=' SEQUENCED VALIDTIME PERIOD '(2007-01-01, 2008-03-01)''
TEMPORAL_QUALIFIER='CURRENT TRANSACTIONTIME'
TEMPORAL_QUALIFIER='TRANSACTIONTIME AS OF TIMESTAMP '2009-01-01 01:02:03.123456' '
If you specify the temporal
qualifier on the LIBNAME, it applies to the entire session because
it is implemented by issuing session commands at connect time. For
example, if you specify
TEMPORAL_QUALIFIER='ASOF PERIOD
'(1999-01-01, 2099-01-05)' '
on the LIBNAME, here is
the Teradata SET SESSION command that is issued at connect time. The
SQL is submitted as usual.
.SET SESSION ASOF PERIOD '(1999-01-01, 2099-01-05)'
If you submit the above
command, the temporal qualifier is added as a prefix, as shown below.
ASOF PERIOD '(1999-01-01, 2099-01-05)'
SELECT * from TEMPORAL_TABLE;
Sample code
-----------
/* PERIOD data types require the Teradata V13 server. */
libname x teradata user=testuser pw=testpw server=td13;
/* Create a table with the PERIOD(DATE) data type.
Note: This is not a temporal table. */
data x.mytest(DBTYPE=(validity='PERIOD(DATE)'));
i=1; validity='(1973-02-03, 9999-12-31)'; output;
run;
/* Read from a table with a PERIOD data type? */
proc print data=x.mytest;
run;
/* Use Fastload to load a table with a PERIOD data type. */
proc datasets library=x;
delete mytest;run;
data x.mytest(DBTYPE=(validity='PERIOD(TIMESTAMP)') FASTLOAD=YES TPT=NO);
i=1; validity='(1970-01-05 01:02:03.123, 1970-01-05 05:06:07.456)'; output;
run;
/* Tempral support starts in Teradata V13.10. */
libname x teradata user=testuser pw=testpw server=td1310;
/* Create a table with the PERIOD(DATE) data type. */
data x.mytest(DBTYPE=(validity='PERIOD(DATE) VALIDTIME'));
i=1; validity='(1973-02-03, 1999-12-31)'; output;
i=2; validity='(2000-01-01, 2011-01-01)'; output;
i=3; validity='(2011-01-02, 9999-12-31)'; output;
run;
/* Can we read a PERIOD data type?
You must select the row with i=2. */
proc print data=x.mytest(TEMPORAL_QUALIFIER='CURRENT VALIDTIME');
run;
/* Consider data as of 1995-01-01. */
libname x teradata user=testuser pw=testpw server=td1310
TEMPORAL_QUALIFIER='VALIDTIME AS OF DATE '1995-01-01' '
/* Row with i=1 is returned. */
proc print data=x.mytest(DBSLICEPARM=ALL);
run;