云数据库 GAUSSDB-使用:示例

时间:2024-11-02 18:48:07

示例

-- 准备数据
CREATE TABLE t1(c1 int, c2 int);
INSERT INTO t1 VALUES(1, 1);
INSERT INTO t1 VALUES(2, 2);

-- 创建全量物化视图
openGauss=# CREATE MATERIALIZED VIEW mv AS select count(*) from t1;
CREATE MATERIALIZED VIEW

-- 查询物化视图结果
openGauss=# SELECT * FROM mv;
 count 
-------
     2
(1 row)

-- 再次向物化视图中基表插入数据
openGauss=# INSERT INTO t1 VALUES(3, 3);

-- 对全量物化视图做全量刷新
openGauss=# REFRESH MATERIALIZED VIEW mv;
REFRESH MATERIALIZED VIEW

-- 查询物化视图结果
openGauss=# SELECT * FROM mv;
 count 
-------
     3
(1 row)

-- 删除物化视图
openGauss=# DROP MATERIALIZED VIEW mv;
DROP MATERIALIZED VIEW
support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-1099.html