MERGE
Grammar Syntax
MERGE INTO target_table
USING source_table [ [ AS ] alias ]
ON match_condition
[ WHEN MATCHED THEN { UPDATE SET col_name = { expr } [,...] | DELETE }
WHEN NOT MATCHED THEN INSERT [ ( col_name [,...] ) ] VALUES ( { expr } [, ...] ) |
REMOVE DUPLICATES ]For more information please refer to Redshift MERGE documentation.
Sample Source Patterns
UPDATE - INSERT
There are no differences between both languages. The code is kept in its original form.
Input Code:
Output Code:
DELETE - INSERT
There are no differences between both languages. The code is kept in its original form.
Input Code:
Output Code:
REMOVE DUPLICATES
The REMOVE DUPLICATES clause is not supported in Snowflake, however, there is a workaround that could emulate the original behavior.
The output code will have three new statements:
A TEMPORARY TABLE with the duplicate values from the source and target table that matches the condition
An INSERT statement that adds the pending values to the target table after the merge
A DROP statement that drops the generated temporary table.
These are necessary since the DROP DUPLICATES behavior removes the duplicate values from the target table and then inserts the values that match the condition from the source table.
Input Code:
30
Daisy
22
Clarence
30
Tony
11
Alice
23
David
Output Code:
22
Clarence
30
Tony
30
Daisy
11
Alice
23
David
Known Issues
There are no known issues.
Related EWIs
SSC-EWI-RS0009: Semantic information not found for the source table.
SSC-FDM-RS0005: Duplicates not allowed in source table.
Last updated
