DELETE
Description
Deletes rows from tables. (Redshift SQL Language Reference Delete Statement).
This syntax is fully supported in Snowflake.
Grammar Syntax
Sample Source Patterns
Setup data
From Clause
Update a table by referencing information from other tables. In Redshift, the FROM keyword is optional, but in Snowflake, it is mandatory. Therefore, it will be added in cases where it's missing.
Input Code:
Output Code:
Where Clause
Restricts updates to rows that match a condition. When the condition returns true, the specified SET columns are updated. The condition can be a simple predicate on a column or a condition based on the result of a subquery. This clause is fully equivalent in Snowflake.
Input Code:
Output Code:
Using Clause
This clause introduces a list of tables when additional tables are referenced in the WHERE clause condition. This clause is fully equivalent in Snowflake.
Input Code:
Output Code:
WITH clause
This clause specifies one or more Common Table Expressions (CTE). The output column names are optional for non-recursive CTEs, but mandatory for recursive ones.
Since this clause cannot be used in an DELETE statement, it is transformed into temporary tables with their corresponding queries. After the DELETE statement is executed, these temporary tables are dropped to clean up, release resources, and avoid name collisions when creating tables within the same session. Additionally, if a regular table with the same name exists, it will take precedence again, since the temporary table has priority over any other table with the same name in the same session.
Non-Recursive CTE
Input Code:
Output Code:
Recursive CTE
Input Code:
Output Code:
Delete Materialized View
In Redshift, you can apply the DELETE statement to materialized views used for streaming ingestion. In Snowflake, these views are transformed into dynamic tables, and the DELETE statement cannot be used on dynamic tables. For this reason, an EWI will be added.
Input Code:
Output Code:
Known Issues
Replicating the functionality of the
WITH
clause requires creating temporary tables mirroring each Common Table Expression (CTE). However, this approach fails if a temporary table with the same name already exists within the current session, causing an error.
Related EWIs
SSC-FDM-0031: Dynamic Table required parameters set by default.
SSC-EWI-RS0008: Delete statement cannot be used on dynamic tables.
Last updated