cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Merge Statement not working

Raghu_Bindingan
New Contributor III

Hi I am trying to use the SQL Merge statement on databricks

MERGE INTO target

USING source

ON source.key = target.key

WHEN MATCHED

UPDATE SET *

WHEN NOT MATCHED

INSERT *

WHEN NOT MATCHED BY SOURCE

DELETE

This is failing with the error [PARSE_SYNTAX_ERROR] Syntax error at or near 'UPDATE'.(line 18, pos 2). I am running my notebook on a cluster that is running Databricks 12.2

Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Raghu_Bindingan
New Contributor III

I was missing the THEN before UPDATE, INSERT and DELETE. This keyword is missing from the documentation on Databricks https://learn.microsoft.com/en-us/azure/databricks/delta/merge

It now works. Thanks

View solution in original post

2 REPLIES 2

UmaMahesh1
Honored Contributor III

Are you using the wildcard for the Update and insert ?

#DAIS2023

Uma Mahesh D

Raghu_Bindingan
New Contributor III

I was missing the THEN before UPDATE, INSERT and DELETE. This keyword is missing from the documentation on Databricks https://learn.microsoft.com/en-us/azure/databricks/delta/merge

It now works. Thanks

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group