ALTER TABLE PARTITION

Function

ALTER TABLE PARTITION modifies table partitioning, including adding, deleting, splitting, merging partitions, and modifying partition attributes.

Precautions

Syntax

Parameter Description

Example

Delete partition P8.

1
ALTER TABLE tpcds.web_returns_p1 DROP PARTITION P8;

Add a partition WR_RETURNED_DATE_SK with values ranging from 2453005 to 2453105.

1
ALTER TABLE tpcds.web_returns_p1 ADD PARTITION P8 VALUES LESS THAN (2453105);

Add a partition WR_RETURNED_DATE_SK with values ranging from 2453105 to MAXVALUE.

1
ALTER TABLE tpcds.web_returns_p1 ADD PARTITION P9 VALUES LESS THAN (MAXVALUE);

Rename the P7 partition as P10.

1
ALTER TABLE tpcds.web_returns_p1 RENAME PARTITION P7 TO P10;

Rename the P6 partition as P11.

1
ALTER TABLE tpcds.web_returns_p1 RENAME PARTITION FOR (2452639) TO P11;

Query rows in the P10 partition.

1
2
3
4
5
SELECT count(*) FROM tpcds.web_returns_p1 PARTITION (P10);
 count  
--------
 9362
(1 row)

Split the P8 partition at 2453010.

1
2
3
4
5
ALTER TABLE tpcds.web_returns_p2 SPLIT PARTITION P8 AT (2453010) INTO
(
        PARTITION P9,
        PARTITION P10
); 

Merge the P6 and P7 partitions into one.

1
ALTER TABLE tpcds.web_returns_p2 MERGE PARTITIONS P6, P7 INTO PARTITION P8;

Modify the migration attribute of a partitioned table.

1
ALTER TABLE tpcds.web_returns_p2 DISABLE ROW MOVEMENT;

Add partitions [5000, 5300), [5300, 5600), [5600, 5900), and [5900, 6000).

1
ALTER TABLE tpcds.startend_pt ADD PARTITION p6 START(5000) END(6000) EVERY(300);

Add the partition p7, specified by MAXVALUE.

1
ALTER TABLE tpcds.startend_pt ADD PARTITION p7 END(MAXVALUE);

Rename the partition where 5950 is located to p71.

1
ALTER TABLE tpcds.startend_pt RENAME PARTITION FOR(5950) TO p71;

Split the partition [4000, 5000) where 4500 is located.

1
ALTER TABLE tpcds.startend_pt SPLIT PARTITION FOR(4500) INTO(PARTITION q1 START(4000) END(5000) EVERY;

Links

CREATE TABLE PARTITION, DROP TABLE