YMatrix
Quick Start
Simulate Time Series Scenarios
Standard Cluster Deployment
Data Modeling
Connecting to The database
Data Writing
Data Migration
Data Query
Maintenance and Monitoring
Performance Tuning
Troubleshooting
Reference Guide
Tool Guide
Data Type
Storage Engine
Execution Engine
Configuration Parameters
SQL Reference
FAQ
Delete rows from the table.
[ WITH [ RECURSIVE ] with_query [, ...] ]
DELETE FROM [ONLY] table [[AS] alias]
[USING usinglist]
[WHERE condition | WHERE CURRENT OF cursor_name]
[RETURNING * | output_expression [[AS] output_name] [, …]]
DELETE Deletes the row that satisfies the WHERE clause from the specified table. If the WHERE clause does not exist, the result is that all rows in the table are deleted. The result is a valid but empty table.
By default, DELETE deletes rows from the specified table and all its subtables. If you only want to delete from the specific table mentioned, you must use the ONLY clause.
There are two ways to delete rows in a table using the information contained in other tables in the database: use subselect, or specify another table in the USING clause. Which technology is more suitable depends on the specific situation.
If the WHERE CURRENT OF clause is specified, the deleted row is the latest row obtained from the specified cursor.
The WHERE CURRENT OF clause is not supported in the copy table.
The optional RETURNING clause causes DELETE to calculate and return a value based on each row that is actually deleted. Any expression that uses the columns of the table and/or columns of other tables mentioned in USING can be calculated. The syntax of the RETURNING list is the same as the syntax of the output list of SELECT.
You must have DELETE privileges on the table to be deleted from it.
Note: By default, the YMatrix database acquires the EXCLUSIVE lock on the table for the DELETE operation on the heap table. When the global deadlock detector is enabled, the locking mode of the DELETE operation on the heap table is ROW EXCLUSIVE.
After successful completion, the DELETE command returns the following command label:
DELETE count
count is the number of rows that have been deleted. If count is 0, the query does not delete any rows (this is not considered an error).
If the DELETE command contains the RETURNING clause, the result will be similar to the result of the SELECT statement, which contains the columns and values defined in the RETURNING list, which are calculated on the rows deleted by the command.
with_query
ONLY
table
alias
usinglist
condition
cursor_name
output_expression
output_name
The YMatrix database allows you to refer to columns of other tables under WHERE conditions by specifying them in the USING clause. For example, name it Hannah from the rank table, you can do this:
DELETE FROM rank USING names WHERE names.id = rank.id AND
name = 'Hannah';
What actually happens here is the join between rank and names, and all successfully joined lines are marked as deleted. This syntax is not a standard syntax. However, this join style is often easier to write and execute than a more standard sub-select style, such as:
DELETE FROM rank WHERE id IN (SELECT id FROM names WHERE name
= 'Hannah');
When using DELETE to delete all rows of a table (for example: DELETE * FROM table;), the YMatrix database adds an implicit TRUNCATE command (when user permissions allow). The added TRUNCATE command frees disk space occupied by deleted rows without VACUUM on the table. This improves the scanning performance of subsequent queries and benefits ELT workloads that are often inserted and deleted in temporary tables.
Direct execution of UPDATE and DELETE commands on specific partitions (subtables) of partitioned tables is not supported. Instead, these commands must be executed on the root partition table (the table created using the CREATE TABLE command).
Remove all films except musicals:
DELETE FROM films WHERE kind <> 'Musical';
Clear table films:
DELETE FROM films;
Delete completed tasks and return the full details of the deleted rows:
DELETE FROM tasks WHERE status = 'DONE' RETURNING *;
Use join to delete:
DELETE FROM rank USING names WHERE names.id = rank.id AND
name = 'Hannah';
This command is SQL-compliant, with the difference being that the USING and RETURNING clauses are YMatrix database extensions and the ability to use WITH and DELETE together.