数据仓库服务 GAUSSDB(DWS)-CREATE MATERIALIZED VIEW:示例

时间:2024-11-12 09:33:23

示例

创建基表,并向基表插入数据:

1
2
CREATE TABLE t1 (a int, b int) DISTRIBUTE BY HASH(a);
INSERT INTO t1 SELECT x,x FROM generate_series(1,10) x;

创建默认BUILD IMMEDIATE方式的物化视图:

1
CREATE MATERIALIZED VIEW mv1 AS SELECT * FROM t1;

创建指定列存方式的物化视图:

1
CREATE MATERIALIZED VIEW mv2 WITH(orientation = column) AS SELECT * FROM t1;

创建手动按需刷新的物化视图:

1
CREATE MATERIALIZED VIEW mv3 BUILD DEFERRED REFRESH ON DEMAND AS SELECT * FROM t1;

创建指定刷新时间的物化视图:

1
CREATE MATERIALIZED VIEW mv4 BUILD DEFERRED REFRESH START WITH(trunc(sysdate)) EVERY (interval1 day) AS SELECT * FROM t1;
support.huaweicloud.com/sqlreference-830-dws/dws_06_0357.html