云数据库 GAUSSDB-TRUNCATE:示例

时间:2024-01-23 20:08:47

示例

1
2
3
4
5
6
7
8
--创建表。
postgres=# CREATE TABLE tpcds.reason_t1 AS TABLE tpcds.reason;

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

--删除表。
postgres=# DROP TABLE tpcds.reason_t1;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--创建分区表。
postgres=# 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)
);

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

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

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

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

--删除表。
postgres=# DROP TABLE tpcds.reason_p;
support.huaweicloud.com/devg-v1-gaussdb/gaussdb_devg_0642.html