HomeMogDBMogDB StackUqbar
v2.0

Documentation:v2.0

Supported Versions:

DELETE

Function

DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is absent, the effect is to delete all rows in the table. The result is a valid, but an empty table.

Precautions

  • You must have the DELETE permission on the table to delete from it, as well as the SELECT permission for any table in the USING clause or whose values are read in the condition.
  • For column-store tables, the RETURNING clause is currently not supported.

Syntax

Delete ::= [ WITH [ RECURSIVE ] with_query [, ...] ]
DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    [ USING using_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING { * | { output_expr [ [ AS ] output_name ] } [, ...] } ];

Parameter Description

  • WITH [ RECURSIVE ] with_query [, …]

    Specifies one or more subqueries that can be referenced by name in the main query, which is equivalent to a temporary table.

    If RECURSIVE is specified, it allows a SELECT subquery to reference itself by name.

    Format of with_query:

    with_query_name [ ( column_name [, ...] ) ] AS
    
    ( {select | values | insert | update | delete} )
    • with_query_name specifies the name of the result set generated by a subquery. Such names can be used to access the subquery result set.
    • column_name specifies the column name displayed in the subquery result set.
    • Each subquery can be a SELECT, VALUES, INSERT, UPDATE or DELETE statement.
  • ONLY

    If ONLY is specified before the table name, matching rows are deleted from the named table only. If ONLY is not specified, matching rows are also deleted from any tables inheriting from the named table.

  • table_name

    Specifies the name (optionally schema-qualified) of the target table.

    Value range: an existing table name

  • alias

    Specifies a substitute name for the target table.

    Value range: a string. It must comply with the naming convention rule.

  • using_list

    Specifies the USING clause.

  • condition

    Specifies an expression that returns a Boolean value. Only rows for which this expression returns true will be deleted.

  • WHERE CURRENT OF cursor_name

    This parameter is reserved.

  • output_expr

    Specifies an expression to be computed and returned by the DELETE statement after each row is deleted. The expression can use any column names of the table. Write ***** to return all columns.

  • output_name

    Specifies a name to use for a returned column.

    Value range: a string. It must comply with the naming convention rule.

Examples

-- Create the tpcds.customer_address_bak table.
mogdb=# CREATE TABLE tpcds.customer_address_bak AS TABLE tpcds.customer_address;

-- Delete employees whose ca_address_sk is smaller than 14888 from the tpcds.customer_address_bak table.
mogdb=# DELETE FROM tpcds.customer_address_bak WHERE ca_address_sk < 14888;

-- Delete all data from the tpcds.customer_address_bak table.
mogdb=# DELETE FROM tpcds.customer_address_bak;

Delete the tpcds.customer_address_bak table.
mogdb=# DROP TABLE tpcds.customer_address_bak;

Suggestions

  • delete

    To delete all records in a table, use the truncate syntax.

Copyright © 2011-2024 www.enmotech.com All rights reserved.