云数据库 GAUSSDB-SNAPSHOT:示例

时间:2024-11-02 18:50:37

示例

——创建数据表
gaussdb=# CREATE TABLE t1 (id int, name varchar);

——插入数据
gaussdb=# INSERT INTO t1 VALUES (1, 'zhangsan');
gaussdb=# INSERT INTO t1 VALUES (2, 'lisi');
gaussdb=# INSERT INTO t1 VALUES (3, 'wangwu');
gaussdb=# INSERT INTO t1 VALUES (4, 'lisa');
gaussdb=# INSERT INTO t1 VALUES (5, 'jack');

——创建快照
gaussdb=# CREATE SNAPSHOT s1@1.0 comment is 'first version' AS SELECT * FROM t1;

——迭代创建快照
gaussdb=# CREATE SNAPSHOT s1@2.0 FROM @1.0 comment is 'inherits from @1.0' USING (INSERT VALUES(6, 'john'), (7, 'tim'); DELETE WHERE id = 1);

——查看快照内容
gaussdb=#SELECT * FROM DB4AISHOT(s1@1.0);

——快照采样
gaussdb=# SAMPLE SNAPSHOT s1@2.0 stratify by name as nick at ratio .5;

——删除快照
gaussdb=# PURGE SNAPSHOT s1@2.0;
gaussdb=# PURGE SNAPSHOT s1nick@2.0;
gaussdb=# PURGE SNAPSHOT s1@1.0;

——删除表格
gaussdb=# DROP TABLE t1;
support.huaweicloud.com/centralized-devg-v3-gaussdb/gaussdb-12-0649.html