DELETE
Description
Deletes rows from tables. (Redshift SQL Language Reference Delete Statement).
This syntax is fully supported in Snowflake.
Grammar Syntax
[ WITH [RECURSIVE] common_table_expression [, common_table_expression , ...] ]
DELETE [ FROM ] { table_name | materialized_view_name }
[ USING table_name, ... ]
[ WHERE condition ]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:
1
Alice
Sales
2
2
Bob
Sales
1
3
Charlie
Sales
1
7
Grace
Engineering
6
8
Helen
Engineering
7
9
Ivy
Engineering
7
10
John
Sales
3
11
Joe
Engineering
5
Output Code:
1
Alice
Sales
2
2
Bob
Sales
1
3
Charlie
Sales
1
7
Grace
Engineering
6
8
Helen
Engineering
7
9
Ivy
Engineering
7
10
John
Sales
3
11
Joe
Engineering
5
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:
4
David
Marketing
2
5
Eve
Marketing
4
6
Frank
Marketing
4
7
Grace
Engineering
6
8
Helen
Engineering
7
9
Ivy
Engineering
7
11
Joe
Engineering
5
Output Code:
4
David
Marketing
2
5
Eve
Marketing
4
6
Frank
Marketing
4
7
Grace
Engineering
6
8
Helen
Engineering
7
9
Ivy
Engineering
7
11
Joe
Engineering
5
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:
4
David
Marketing
2
5
Eve
Marketing
4
6
Frank
Marketing
4
Output Code:
4
David
Marketing
2
5
Eve
Marketing
4
6
Frank
Marketing
4
Recursive CTE
Input Code:
1
Alice
Sales
2
2
Bob
Sales
1
3
Charlie
Sales
1
10
John
Sales
3
Output Code:
1
Alice
Sales
2
2
Bob
Sales
1
3
Charlie
Sales
1
10
John
Sales
3
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
WITHclause 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
