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

snowflake.snowpark.Table.delete

Table.delete(condition: Optional[Column] = None, source: Optional[DataFrame] = None, *, statement_params: Optional[Dict[str, str]] = None, block: bool = True) DeleteResult[source]
Table.delete(condition: Optional[Column] = None, source: Optional[DataFrame] = None, *, statement_params: Optional[Dict[str, str]] = None, block: bool = False) snowflake.snowpark.AsyncJob

Deletes rows in a Table and returns a DeleteResult, representing the number of rows deleted.

Parameters:
  • condition – An optional Column object representing the specified condition. It must be provided if source is provided.

  • source – An optional DataFrame that is included in condition. It can also be another Table.

  • statement_params – Dictionary of statement level parameters to be set while executing this action.

  • block – A bool value indicating whether this function will wait until the result is available. When it is False, this function executes the underlying queries of the dataframe asynchronously and returns an AsyncJob.

Examples:

>>> target_df = session.create_dataframe([(1, 1),(1, 2),(2, 1),(2, 2),(3, 1),(3, 2)], schema=["a", "b"])
>>> target_df.write.save_as_table("my_table", mode="overwrite", table_type="temporary")
>>> t = session.table("my_table")

>>> # delete all rows in a table
>>> t.delete()
DeleteResult(rows_deleted=6)
>>> t.collect()
[]

>>> # delete all rows where column "a" has value 1
>>> target_df.write.save_as_table("my_table", mode="overwrite", table_type="temporary")
>>> t.delete(t["a"] == 1)
DeleteResult(rows_deleted=2)
>>> t.sort("a", "b").collect()
[Row(A=2, B=1), Row(A=2, B=2), Row(A=3, B=1), Row(A=3, B=2)]

>>> # delete all rows in this table where column "a" in this
>>> # table is equal to column "a" in another dataframe
>>> target_df.write.save_as_table("my_table", mode="overwrite", table_type="temporary")
>>> source_df = session.create_dataframe([2, 3, 4, 5], schema=["a"])
>>> t.delete(t["a"] == source_df.a, source_df)
DeleteResult(rows_deleted=4)
>>> t.sort("a", "b").collect()
[Row(A=1, B=1), Row(A=1, B=2)]
Copy