云数据库 GAUSSDB-TRUNCATE:示例

时间:2024-11-02 18:53:06

示例

--创建表。
openGauss=# CREATE TABLE tpcds.reason_t1 AS TABLE tpcds.reason;

--清空表tpcds.reason_t1。
openGauss=# TRUNCATE TABLE tpcds.reason_t1;

--删除表。
openGauss=# DROP TABLE tpcds.reason_t1;
--创建分区表。
openGauss=# CREATE TABLE tpcds.reason_p
(
  r_reason_sk integer,
  r_reason_id character(16),
  r_reason_desc character(100)
)PARTITION BY RANGE (r_reason_sk)
(
  partition p_05_before values less than (05),
  partition p_15 values less than (15),
  partition p_25 values less than (25),
  partition p_35 values less than (35),
  partition p_45_after values less than (MAXVALUE)
);

--插入数据。
openGauss=# INSERT INTO tpcds.reason_p SELECT * FROM tpcds.reason;

--清空分区p_05_before。
openGauss=# ALTER TABLE tpcds.reason_p TRUNCATE PARTITION p_05_before;

--清空分区p_15。
openGauss=# ALTER TABLE tpcds.reason_p TRUNCATE PARTITION for (13);

--清空分区表。
openGauss=# TRUNCATE TABLE tpcds.reason_p;

--删除表。
openGauss=# DROP TABLE tpcds.reason_p;
support.huaweicloud.com/centralized-devg-v2-gaussdb/devg_03_0672.html