You are viewing documentation about an older version (1.12.1). View latest version

snowflake.snowpark.WhenMatchedClause.delete

WhenMatchedClause.delete()[source]

Defines a delete action for the matched clause and returns an updated WhenMatchedClause with the new delete action added.

Example:

>>> # Adds a matched clause where a row in source is matched
>>> # if its key is equal to the key of any row in target.
>>> # For all such rows, delete them.
>>> from snowflake.snowpark.functions import when_matched
>>> target_df = session.create_dataframe([(10, "old"), (10, "too_old"), (11, "old")], schema=["key", "value"])
>>> target_df.write.save_as_table("my_table", mode="overwrite", table_type="temporary")
>>> target = session.table("my_table")
>>> source = session.create_dataframe([(10, "new")], schema=["key", "value"])
>>> target.merge(source, target["key"] == source["key"], [when_matched().delete()])
MergeResult(rows_inserted=0, rows_updated=0, rows_deleted=2)
>>> target.collect() # the rows are deleted
[Row(KEY=11, VALUE='old')]
Copy

Note

An exception will be raised if this method or WhenMatchedClause.update() is called more than once on the same WhenMatchedClause object.