Merge with TIMESTAMP column PK

General
Enthusiast

Merge with TIMESTAMP column PK

Hi everyone.

I need to merge some data what i  have a 3 column's UPI (col1,col2,col3), col 1 and col2 are a varchar but col3 it's a timestamp.

Im trying to merge but teradata studio show me an error, what i have a pk duplicated.

I test before with count and count distinct using only the UPI columns and i dont have any duplicated

I think the problem its the timestamp column because i tested using like pk in the merge only col1 and col2(Varchar columns) and there are not problem but the data merged its not correct because i need the other column.

I used this script:

MERGE INTO DATALAB.TABLE  A

 using (select col4, col5, col6, col1, col2, col3, col7, col8 FROM DATALAB.TABLE) AS B

ON A.col1 = B.col1

AND A.col2 = B.col2

AND A.col3 = B.col3

WHEN MATCHED THEN

UPDATE SET

col4 = B.col4,

col5 = B.col5,

col6 = B.col6,

col7 = B.col7,

col8 = B.col8,

DA_CHARGE = A.DA_CHARGE,

DA_MODI = cast(current_timestamp(0) as timestamp(0))

WHEN NOT MATCHED THEN

INSERT (A.col4,A.col5,A.col6,A.col1,A.col2,A.col3,A.col7,A.col8)

VALUES (B.col4,B.col5,B.col6,B.col1,B.col2,B.col3,B.col7,B.col8);

Thanks in advance

1 REPLY
Enthusiast

Re: Merge with TIMESTAMP column PK

Sorry its OK, the problem was i was trying to merge the same data, i update the info to merge and there no problem