MERGE needs its own schema evolution switch
Delta's mergeSchema option does nothing for MERGE statements — automatic schema evolution for MERGE is a separate session setting.
The takeaway
option("mergeSchema", "true") only applies to writes (append/overwrite). A MERGE INTO that should add new source columns to the target needs:
SET spark.databricks.delta.schema.autoMerge.enabled = true;or, on newer runtimes, the explicit WHEN NOT MATCHED THEN INSERT * with schema evolution enabled on the table operation.
Context
A CDC feed added a discount_code column upstream. The nightly MERGE kept succeeding — and silently dropping the new column, because UPDATE SET * and INSERT * resolve against the target schema.
Example
SET spark.databricks.delta.schema.autoMerge.enabled = true;
MERGE INTO silver.orders t
USING staged_updates s
ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;
-- discount_code now lands as a new nullable columnWhy it matters
Silently dropped columns are the worst kind of failure: no error, wrong data, discovered weeks later. If your source schemas drift, decide explicitly — auto-merge on, or a schema check that fails loudly.
Go deeper
- Related article: Delta Lake MERGE without the full-table rewrite
Keep going
Delta Lake MERGE without the full-table rewrite
Why MERGE quietly rewrites far more data than it changes, and the three fixes that keep it fast: prune the target, deduplicate the source, compact after.
Delta Lake Interview Questions: 25 Scenario Problems with Answers
25 scenario-based Delta Lake interview questions in five areas, with what the interviewer is checking and a strong answer for each.
Deduplicate Late-Arriving CDC Rows with MERGE: A Worked Problem
A CDC feed sends duplicates and out-of-order changes. Build a MERGE that keeps the latest row per key, ignores late events and is safe to replay.
One practical note a week
Get new articles, problems and guides in your inbox.
Thanks! You're on the list. (Local demo — no email provider is wired up yet.)