Azure Synapse Merge Command is failing with exception - "Updating a distribution key column in a MERGE statement is not supported."

Rahul Glenn Rajkumar 1 Reputation point
2022-08-04T13:15:02.19+00:00

I am trying to merge a target table with a source table based on some conditions. It is supposed to insert the records from the source table to the target table. Though it won't update the distribution key, it keeps failing with the exception, "Updating a distribution key column in a MERGE statement is not supported".

Azure Synapse Version:
Microsoft Azure SQL Data Warehouse - 10.0.15665.0 Jul 9 2022 10:38:42 Copyright (c) Microsoft Corporation

Target Table DDL:
create table "infra760"."qatest"."testtable"(
ID int,
COl1 numeric(38,0)
)with(
distribution = HASH(ID)
);

Source Table DDL:
CREATE TABLE "infra760"."qatest"."stagetable" (
"ID" int,
"COL1" numeric(38,0),
SEQNO BigInt,
ISDELETED BIT
);

DMLS Executed on Source Table:
insert into "infra760"."qatest"."stagetable" values(1,1,0,0);

Merge Query:
MERGE INTO "infra760"."QATEST"."testtable" as Target USING "infra760"."qatest"."stagetable" AS S ON S."ID" = Target."ID"
WHEN NOT MATCHED BY Target AND ISDELETED = 0 THEN INSERT ("ID","COL1") VALUES(S."ID",S."COL1")
WHEN MATCHED AND ISDELETED = 1 THEN DELETE
WHEN MATCHED AND ISDELETED = 0 THEN UPDATE SET Target."ID"=S."ID",Target."COL1"=S."COL1";

Note:
The Target Table is Empty while the Source Table has just one record in it.

Data in Source Table :
228090-screenshot-2022-08-04-at-64344-pm.png

The same merge query was working fine earlier. All of a sudden, it started to fail with this exception.

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,558 questions
{count} votes