Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-40921

Add WHEN NOT MATCHED BY SOURCE clause to MERGE INTO command

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.0
    • 3.4.0
    • SQL
    • None

    Description

      The MERGE INTO syntax in Spark allows two types of WHEN clause:

      • WHEN MATCHED: Specify optional condition and actions (delete or update) to apply to rows that satisfy the merge condition.
      • WHEN NOT MATCHED: Specify optional condition and actions (insert) to apply toi rows from the source table that don't satisfy the match condition.

      Other products also offer a third type of WHEN clause:

      • WHEN NOT MATCHED BY SOURCE: Specify optional condition and actions (delete or update) to apply to rows from the target table that don't satisfy the merge condition.

      See for example T-SQL Merge Documentation

      Example:

      MERGE INTO target
      USING source
      ON target.key = source.key
      WHEN MATCHED THEN UPDATE SET *
      WHEN NOT MATCHED THEN INSERT *
      WHEN NOT MATCHED BY SOURCE THEN DELETE 

       

      Attachments

        Activity

          People

            johanl-db Johan Lasperas
            johanl-db Johan Lasperas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: