I am facing an issue while performing a MERGE operation on my Delta table. The error message I receive is:
Cannot perform Merge as multiple source rows matched and attempted to
modify the same target row in the Delta table in possibly conflicting
ways.
I have verified that there are no duplicates in the primary key of my target table.
Data Insertion: Initially, I inserted some input data successfully.
However, when I attempt to insert the same data again, I get this error.
Here’s a simplified version of the SQL code I am using for the MERGE operation:
MERGE INTO target_table AS t
USING source_table AS s
ON t.primary_key = s.primary_key
WHEN MATCHED THEN
UPDATE SET t.column1 = s.column1, t.column2 = s.column2
WHEN NOT MATCHED THEN
INSERT (primary_key, column1, column2) VALUES (s.primary_key, s.column1, s.column2)
What could cause multiple source rows to match the same target row, even when there are no duplicates in my primary key?
How can I preprocess the source data to prevent this issue?
You need to sign in to view this answers