Example: Override TD_TIMECODE as the DEFAULT TIMECODE Column - Advanced SQL Engine - Teradata Database

Time Series Tables and Operations

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
cxa1555383531762.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1208
lifecycle
previous
Product Category
Teradata Vantageā„¢

PTI tables have their own timecode column. To override TD_TIMECODE as the default timecode column, specify it in the USING TIMECODE clause. For example, suppose the OCEAN_BUOYS table had another column called my_timecode that was of TIMESTAMP(6) type. Note that when the USING TIMECODE clause is not specified, the timecode column is the default system generated TD_TIMECODE column when a PTI table is given in the query:

-- use default timecode TD_TIMECODE
select avg(temperature)
from ocean_buoys
group by time(minutes(10));
  
-- override default
create table my_ocean_buoys as ocean_buoys with no data;
alter table my_ocean_buoys add my_timecode timestamp(6);
show table my_ocean_buoys;
CREATE SET TABLE my_ocean_buoys ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      TD_TIMEBUCKET BIGINT NOT NULL GENERATED SYSTEM TIMECOLUMN,
      TD_TIMECODE TIMESTAMP(6) NOT NULL GENERATED TIMECOLUMN,
      BUOYID INTEGER,
      SALINITY INTEGER,
      TEMPERATURE INTEGER,
      my_timecode TIMESTAMP(6))
PRIMARY TIME INDEX (TIMESTAMP(6), DATE '2012-01-01', HOURS(1), COLUMNS(BUOYID), NONSEQUENCED);

-- use my_timecode instead of TD_TIMECODE. 
select avg(temperature)
from my_ocean_buoys
group by time(minutes(100))
using timecode(my_timecode);