Medium severityquery
Power BI Refresh Error:
NON_LAST_MATCHED_CLAUSE_OMIT_RESULT
What does this error mean?
A MERGE INTO statement contains a WHEN MATCHED clause that does not produce an action (INSERT/UPDATE/DELETE) and is not the last MATCHED clause. Databricks requires that only the final MATCHED clause can omit an action.
Common causes
- 1MERGE INTO written with a WHEN MATCHED clause that has no THEN action, placed before another MATCHED clause
- 2Migrating MERGE syntax from SQL Server or Oracle where the ordering rules differ
- 3A conditional MATCHED clause intended to 'skip' rows being placed in a non-terminal position
- 4Auto-generated MERGE SQL from an ORM or ETL framework producing clauses in the wrong order
How to fix it
- 1Move the WHEN MATCHED clause that omits an explicit action to be the last MATCHED clause in the MERGE statement
- 2Add an explicit `THEN DO NOTHING` (or equivalent no-op) to intermediate MATCHED clauses if your intent is to skip certain rows
- 3Review the MERGE clause ordering: WHEN MATCHED clauses are evaluated top-to-bottom and only the first matching clause fires per row
- 4If skipping rows is the intent, use a negated condition on the preceding MATCHED clause instead