存在外键时记录错误失败

Logging error fails when there is a foreign key

当存在外键约束时,我无法使用 LOGGING ERRORS 功能。我做错了什么?

这是我的例子:

/*
DROP TABLE DM_CALIDAD.AMK_ACCT_DTL_DATA;
DROP TABLE DM_CALIDAD.AMK_ACCT_DTL_ERR;
DROP TABLE DM_CALIDAD.AMK_ACCT_DTL;
DROP TABLE DM_CALIDAD.AMK_ACCT_ANC;
*/

-- Create parent table 
CREATE SET TABLE DM_CALIDAD.AMK_ACCT_ANC ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      ACCT_ID INTEGER NOT NULL,
      LOAD_TS TIMESTAMP(6) NOT NULL)
UNIQUE PRIMARY INDEX ACCT_ANC_UPI ( ACCT_ID );

-- Create child table
CREATE SET TABLE DM_CALIDAD.AMK_ACCT_DTL ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      ACCT_ID INTEGER NOT NULL,
      ACCT_DTL_ID INTEGER NOT NULL,
      LOAD_TS TIMESTAMP(6) NOT NULL, 
FOREIGN KEY ( ACCT_ID ) REFERENCES DM_CALIDAD.AMK_ACCT_ANC ( ACCT_ID ))
UNIQUE PRIMARY INDEX ACCT_DTL_UPI ( ACCT_ID ,ACCT_DTL_ID );

-- Create data table to use with insert/select. Same as child, but no FK
CREATE SET TABLE DM_CALIDAD.AMK_ACCT_DTL_DATA ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      ACCT_ID INTEGER NOT NULL,
      ACCT_DTL_ID INTEGER NOT NULL,
      LOAD_TS TIMESTAMP(6) NOT NULL)
UNIQUE PRIMARY INDEX ACCT_DTL_DATA_UPI ( ACCT_ID ,ACCT_DTL_ID );

-- Create error table
CREATE ERROR TABLE DM_CALIDAD.AMK_ACCT_DTL_ERR FOR DM_CALIDAD.AMK_ACCT_DTL;

--Insert data on parent and data tables.
INSERT INTO DM_CALIDAD.AMK_ACCT_ANC VALUES(1, current_timestamp);
INSERT INTO DM_CALIDAD.AMK_ACCT_DTL_DATA VALUES(1, 1, current_timestamp);
INSERT INTO DM_CALIDAD.AMK_ACCT_DTL_DATA VALUES(2, 1, current_timestamp); -- This will fail

--Insert/select into the child table
INSERT INTO DM_CALIDAD.AMK_ACCT_DTL 
  SELECT * FROM DM_CALIDAD.AMK_ACCT_DTL_DATA 
  LOGGING ALL ERRORS WITH NO LIMIT;

-- The insert/select fails with the next error
--STATEMENT 1: Insert Statement failed.  Failed [9127 : HY000] Index violations detected; errors logged in AMK_ACCT_DTL_ERR where ETC_dbql_qid = 307181783828932305.

如何将有效行插入子 table 并将无效行插入错误 table?

谢谢!

Logging Errors 不支持 FK 违规,请参阅 Logging Errors For INSERT … SELECT Requests

的手册
When Teradata Database encounters USI or RI errors (or both) in the INSERT … SELECT operation, the following events occur in sequence:
1. The transaction or request runs to completion.
2. The system writes all error-causing rows into the error table.
3. The system aborts the transaction or request.
4. The system rolls back the transaction or request.