17.00 - Example: Override TD_TIMECODE as the DEFAULT TIMECODE Column - Teradata Database

Teradata Vantageā„¢ - Time Series Tables and Operations

prodname
Advanced SQL Engine
Teradata Database
vrm_release
17.00
created_date
June 2020
category
Programming Reference
featnum
B035-1208-170K

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);