MERGE

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

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:

Output Code:

Known Issues

There are no known issues.

  1. SSC-EWI-RS0009: Semantic information not found for the source table.

  2. SSC-FDM-RS0005: Duplicates not allowed in source table.

Last updated