Repository: tobymao/sqlglot

Issue:
Support for Merge
Hi there!

I have a t-sql merge statement:

```sql
MERGE [CORE].[DIM_BusinessUnit] a
			USING [TRANSF].[Merge_BusinessUnit] b
			             ON a.[IdDWH] = b.[IdDWH]
			
			WHEN MATCHED AND EXISTS
			(
				SELECT a.[Name]
					   
				EXCEPT
			        
				SELECT b.[Name]
			
			)
			THEN 
			UPDATE SET     a.[Name]			 =  b.[Name]
						  ;
```

seems to be unparseable

Enough issues for a while now ;) sqlglot is great and already helping me a lot

Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index dff01ca4..e44be570 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -3076,7 +3076,7 @@ class Parser(metaclass=_Parser):
 
     def _parse_merge(self) -> exp.Expression:
         self._match(TokenType.INTO)
-        target = self._parse_table(schema=True)
+        target = self._parse_table()
 
         self._match(TokenType.USING)
         using = self._parse_table()


Test patch:
diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py
index b2f46766..b23711bc 100644
--- a/tests/dialects/test_dialect.py
+++ b/tests/dialects/test_dialect.py
@@ -1365,3 +1365,19 @@ SELECT
                 "spark": "MERGE INTO target USING source ON target.id = source.id WHEN MATCHED THEN UPDATE * WHEN NOT MATCHED THEN INSERT *",
             },
         )
+        self.validate_all(
+            """
+            MERGE a b USING c d ON b.id = d.id
+            WHEN MATCHED AND EXISTS (
+                SELECT b.name
+                EXCEPT
+                SELECT d.name
+            )
+            THEN UPDATE SET b.name = d.name
+            """,
+            write={
+                "bigquery": "MERGE INTO a AS b USING c AS d ON b.id = d.id WHEN MATCHED AND EXISTS(SELECT b.name EXCEPT DISTINCT SELECT d.name) THEN UPDATE SET b.name = d.name",
+                "snowflake": "MERGE INTO a AS b USING c AS d ON b.id = d.id WHEN MATCHED AND EXISTS(SELECT b.name EXCEPT SELECT d.name) THEN UPDATE SET b.name = d.name",
+                "spark": "MERGE INTO a AS b USING c AS d ON b.id = d.id WHEN MATCHED AND EXISTS(SELECT b.name EXCEPT SELECT d.name) THEN UPDATE SET b.name = d.name",
+            },
+        )