使用
语法格式
创建增量物化视图
CREATE INCREMENTAL MATERIALIZED VIEW [ view_name ] AS { query_block };
全量刷新物化视图
REFRESH MATERIALIZED VIEW [ view_name ];
增量刷新物化视图
REFRESH INCREMENTAL MATERIALIZED VIEW [ view_name ];
删除物化视图
DROP MATERIALIZED VIEW [ view_name ];
查询物化视图
SELECT * FROM [ view_name ];
示例
1、创建测试表并插入数据。
CREATE TABLE t1(c1 int, c2 int);
INSERT INTO t1 VALUES(1, 1);
INSERT INTO t1 VALUES(2, 2);
2、创建增量物化视图。
CREATE INCREMENTAL MATERIALIZED VIEW mv AS SELECT * FROM t1;
3、插入数据并增量刷新物化视图。
INSERT INTO t1 VALUES(3, 3);
REFRESH INCREMENTAL MATERIALIZED VIEW mv;
4、查询物化视图结果。
SELECT * FROM mv;
返回结果为:
c1 | c2
----+----
1 | 1
2 | 2
3 | 3
(3 rows)
5、插入数据并全量刷新物化视图。
INSERT INTO t1 VALUES(4, 4);
REFRESH MATERIALIZED VIEW mv;
6、查询物化视图结果。
select * from mv;
返回结果为:
c1 | c2
----+----
1 | 1
2 | 2
3 | 3
4 | 4
(4 rows)
7、删除物化视图。
DROP MATERIALIZED VIEW mv;
相关链接
CREATE INCREMENTAL MATERIALIZED VIEW、REFRESH INCREMENTAL MATERIALIZED VIEW 、DROP MATERIALIZED VIEW