MERGE Statement
Translation reference to convert Oracle MERGE statement to Snowflake Scripting
Some parts in the output code are omitted for clarity reasons.
Description
The
MERGE
statement is used to select rows from one or more sources for update or insertion into a table or view. It is possible to specify conditions to determine whether to update or insert into the target table or view. This statement is a convenient way to combine multiple operations. It lets to avoid multipleINSERT
,UPDATE
, andDELETE
DML statements.MERGE
is a deterministic statement. It is not possible to update the same row of the target table multiple times in the sameMERGE
statement. (Oracle PL/SQL Language Reference MERGE Statement))
Sample Source Patterns
Sample auxiliary data
This code was executed for a better understanding of the examples:
MERGE Statement simple case
Oracle
Snowflake
MERGE Statement with DELETE and where clause
In order to find an equivalence for the DELETE statement and the where clause, it is necessary to reorder and implement some changes in the Snowflake merge statement.
Changed required:
Replace the Oracle's DELETE where_clause with a new Snowflake's matchedClause with the AND predicate statement
Replace the where_clause from the Oracle's merge_insert_clause with an AND predicate statement in the Snowflake's notMatchedClause
Oracle
Snowflake
In some cases the changes applied may do not work as expected, like the next example:
Oracle
Snowflake
Known Issues
1. Oracle's error_logging_clause is not supported
There is no equivalent for the error logging clause in Snowflake Scripting.
2. Changed applied do not work as expected
Sometimes the changes applied in order to achieve the functional equivalence between Oracle's merge statement and Snowflake's, do not work as expected.
Related EWIs
SSC-FDM-OR0018: Merge statement may not work as expected
Last updated