- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2025 07:22 AM
Hi @Shruti12 ,
Yes it does. Check below example, in this case one row from source_table caused an updated of 2 matching rows in target_table.
%sql
CREATE OR REPLACE TABLE default.target_table (
id INT,
category STRING,
value STRING
) USING DELTA;
INSERT INTO target_table VALUES
(1, 'A', 'old'),
(2, 'A', 'old'),
(3, 'B', 'old');
%sql
CREATE OR REPLACE TABLE default.source_table (
category STRING,
new_value STRING
) USING DELTA;
INSERT INTO source_table VALUES
('A', 'new');
%sql
MERGE INTO target_table AS target
USING source_table AS source
ON target.category = source.category
WHEN MATCHED THEN
UPDATE SET value = source.new_value;
But your error suggests different scenario. It seems that in your data you have multiple source rows that match one target row. In that case you have ambiguity and merge will not work.
In DBR 16.1 + they improve functionality of MERGE operations where multiple rows of the source dataset match the same row of the target Delta table, but only one row matches the WHEN MATCHED condition. In the past, these operations would fail with DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE. Prior DBR’s MERGE would only use the MERGE conditions to detect multiple rows from the source dataset trying to update the target dataset leading to ambiguity. This improved functionality allows for the WHEN MATCHED condition to help resolve the ambiguity. You can read about this under following post:
Improved Duplicate Match Handling in Delta MERGE O... - Databricks Community - 106537