DELETE

Function

DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause does not exist, all rows in the table will be deleted. The result is a valid, but an empty table.

Precautions

Syntax

1
2
3
4
5
[ 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

Examples

Create a range partitioned table customer_address_bak:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
DROP TABLE IF EXISTS customer_address_bak;
CREATE TABLE customer_address_bak
(
    ca_address_sk       INTEGER                  NOT NULL   ,
    ca_address_id       CHARACTER(16)            NOT NULL   ,
    ca_street_number    CHARACTER(10)                       ,
    ca_street_name      CHARACTER varying(60)               ,
    ca_street_type      CHARACTER(15)                       ,
    ca_suite_number     CHARACTER(10)                    
)
DISTRIBUTE BY HASH (ca_address_sk)
PARTITION BY RANGE(ca_address_sk)
(
        PARTITION P1 VALUES LESS THAN(2450815),
        PARTITION P2 VALUES LESS THAN(2451179),
        PARTITION P3 VALUES LESS THAN(2451544),
        PARTITION P4 VALUES LESS THAN(MAXVALUE)
);

Delete employees whose ca_address_sk is less than 14888 in the tpcds.customer_address_bak table:

1
DELETE FROM customer_address_bak WHERE ca_address_sk < 14888;

Delete the employees whose ca_address_sk is 14891, 14893, and 14895 from tpcds. customer_address_bak:

1
DELETE FROM customer_address_bak WHERE ca_address_sk in (14891,14893,14895);

Delete all data in customer_address_bak:

1
DELETE FROM customer_address_bak;