0

I have such table:

CREATE SET TABLE ONLINE_BANKING.TRANSACTIONS ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      transaction_id INTEGER NOT NULL,
      date_of_transaction DATE FORMAT 'YYYYMMDD' NOT NULL,
      amount_of_transaction DECIMAL(38,2) NOT NULL,
      transaction_type_code BYTEINT NOT NULL DEFAULT 25 , 
UNIQUE PRIMARY INDEX ( transaction_id );

I would like to add partition to my filled with data table to date_of_transaction column.

I tried this way:

ALTER TABLE TRANSACTIONS
MODIFY PRIMARY INDEX (date_of_transaction) -- tried to write different columns, but failed
ADD RANGE BETWEEN DATE '1998-01-01' AND DATE '2015-12-31' EACH INTERVAL '1' MONTH;

However Teradata returned error:

DROP RANGE/ADD RANGE clause no corresponding level that is a RANGE_N function

What does it mean and what how can I achieve the goal?

Rocketq
  • 5,423
  • 23
  • 75
  • 126

1 Answers1

2

You can't add partitioning to an existing table which is not partitioned, yet, you can only add or drop ranges from a partitioned table.

The only way is to create a new table and INSERT/SELECT like this:

CREATE SET TABLE ONLINE_BANKING.TRANSACTIONS_PPI ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      transaction_id INTEGER NOT NULL,
      date_of_transaction DATE FORMAT 'YYYYMMDD' NOT NULL,
      amount_of_transaction DECIMAL(38,2) NOT NULL,
      transaction_type_code BYTEINT NOT NULL DEFAULT 25 , 
      ...)
PRIMARY INDEX ( transaction_id )
PARTITION BY
   RANGE_N (date_of_transaction BETWEEN DATE '1998-01-01' AND DATE '2015-12-31' 
   EACH INTERVAL '1' MONTH);

INSERT INTO ONLINE_BANKING.TRANSACTIONS_PPI
SELECT * FROM ONLINE_BANKING.TRANSACTIONS;

-- when everything is ok
DROP TABLE ONLINE_BANKING.TRANSACTIONS;
RENAME TABLE ONLINE_BANKING.TRANSACTIONS_PPI AS ONLINE_BANKING.TRANSACTIONS;
dnoeth
  • 59,503
  • 4
  • 39
  • 56
  • Thank you for the answer, but I'm missing something. TD keeps saying that ` data type (date_of_transaction) does not match a defined type name teradata`. What is wrong? – Rocketq Mar 08 '16 at 15:46