Help Center/
GaussDB/
Feature Guide(Centralized_8.x)/
Materialized View/
Fast-Refresh Materialized View/
Usage
Updated on 2024-06-07 GMT+08:00
Usage
Syntax
- Create a fast-refresh materialized view.
CREATE INCREMENTAL MATERIALIZED VIEW view_name AS query;
- Completely refresh a materialized view.
REFRESH MATERIALIZED VIEW view_name;
- Fast refresh a materialized view.
REFRESH INCREMENTAL MATERIALIZED VIEW view_name;
- Drop a materialized view.
DROP MATERIALIZED VIEW view_name;
- Query a materialized view.
SELECT * FROM view_name;
Parameters
- view_name
Specifies the name of the materialized view to be created.
Value range: a string. It must comply with the identifier naming convention.
- AS query
Specifies a SELECT or VALUES command, or an EXECUTE command that runs a prepared SELECT or VALUES query.
Examples
-- Change the default type of a table. gaussdb=# set enable_default_ustore_table=off; -- Prepare data. gaussdb=# CREATE TABLE t1(c1 int, c2 int); gaussdb=# INSERT INTO t1 VALUES(1, 1); gaussdb=# INSERT INTO t1 VALUES(2, 2); -- Create a fast-refresh materialized view. gaussdb=# CREATE INCREMENTAL MATERIALIZED VIEW mv AS SELECT * FROM t1; CREATE MATERIALIZED VIEW -- Insert data. gaussdb=# INSERT INTO t1 VALUES(3, 3); INSERT 0 1 -- Fast refresh the materialized view. gaussdb=# REFRESH INCREMENTAL MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW -- Query the materialized view result. gaussdb=# SELECT * FROM mv; c1 | c2 ----+---- 1 | 1 2 | 2 3 | 3 (3 rows) -- Insert data. gaussdb=# INSERT INTO t1 VALUES(4, 4); INSERT 0 1 -- Completely refresh the materialized view. gaussdb=# REFRESH MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW -- Query the materialized view result. gaussdb=# select * from mv; c1 | c2 ----+---- 1 | 1 2 | 2 3 | 3 4 | 4 (4 rows) -- Drop the materialized view and table. gaussdb=# DROP MATERIALIZED VIEW mv; DROP MATERIALIZED VIEW gaussdb=# DROP TABLE t1; DROP TABLE
Parent topic: Fast-Refresh Materialized View
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot