Regarding upsert

Database

Regarding upsert

Please help me regarding the upsert command in Teradata.
i found some points regarding the upsert in Teradata.
Please confirm me if the below comments correct or not.if correct please
privide the syntax for upsert command
-- Insert statement should not containt SELECT Statement
-- Update Statement should not contain subquery
-- Update statement may not reference another table for updates

Thanks & Regards,
Suresh Babu Ch.
1 REPLY
Teradata Employee

Re: Regarding upsert

Hi,

Logically putting UPSERT in one line: If the row exists (same PK), it'll update, if not it'll insert.

Example is as follows:

MERGE INTO
Table1 AS tt
USING
Table1_tmp AS st
ON
tt.PK_Col=st.PK_Col
WHEN MATCHED THEN UPDATE
SET
Col1=st.Col1,
Col2=st.Col2
WHEN NOT MATCHED THEN
INSERT
(
st.PK_Col,
st.Col1,
st.Col2
)
;

For further documentation over it, please refer to documentation.

Regards,

MAC