DELETE
Deletes data rows from a table based on the specified conditions. The table can be a partitioned or non-partitioned table.
For Duplicate Key tables, Aggregate tables, and Unique Key tables, you can delete data from specified partitions. From v2.3, Primary Key tables support complete DELETE...WHERE
semantics, which allows you to delete data rows based on the primary key, any column, or the results of a subquery. From v3.0, StarRocks enriches the DELETE...WHERE
semantics with multi-table joins and common table expressions (CTEs). If you need to join Primary Key tables with other tables in the database, you can reference these other tables in the USING clause or CTE.
Usage notes
- You must have privileges on the table and database you want to perform DELETE.
- Frequent DELETE operations are not recommended. If needed, perform such operations during off-peak hours.
- The DELETE operation only deletes data in the table. The table remains. To drop the table, run DROP TABLE.
- To prevent misoperations from deleting data in the entire table, you must specify the WHERE clause in the DELETE statement.
- The deleted rows are not immediately cleaned. They are marked as "deleted" and will be temporarily saved in Segment. Physically, the rows are removed only after data version merge (compaction) is completed.
- This operation also deletes data of the materialized views that reference this table.
Duplicate Key tables, Aggregate tables, and Unique Key tables
Syntax
DELETE FROM [<db_name>.]<table_name> [PARTITION <partition_name>]
WHERE
column_name1 op { value | value_list } [ AND column_name2 op { value | value_list } ...]
Parameters
Parameter | Required | Description |
---|---|---|
db_name | No | The database to which the destination table belongs. If this parameter is not specified, the current database is used by default. |
table_name | Yes | The table from which you want to delete data. |
partition_name | No | The partition from which you want to delete data. |
column_name | Yes | The column you want to use as the DELETE condition. You can specify one or more columns. |
op | Yes | The operator used in the DELETE condition. The supported operators are = , > , < , >= , <= , != , IN , and NOT IN . |