Help Center/ GaussDB/ Developer Guide(Centralized_V2.0-2.x)/ Materialized View/ Complete-refresh Materialized View/ Usage
Updated on 2025-08-19 GMT+08:00
Usage
Syntax
- Create a complete-refresh materialized view.
CREATE MATERIALIZED VIEW [ view_name ] AS { query_block };
- Completely refresh a materialized view.
REFRESH MATERIALIZED VIEW [ view_name ];
- Delete a materialized view.
DROP MATERIALIZED VIEW [ view_name ];
- Query a materialized view.
SELECT * FROM [ view_name ];
Examples
-- Prepare data.
openGauss=# CREATE TABLE t1(c1 int, c2 int);
openGauss=# INSERT INTO t1 VALUES(1, 1);
openGauss=# INSERT INTO t1 VALUES(2, 2);
-- Create a complete-refresh materialized view.
openGauss=# CREATE MATERIALIZED VIEW mv AS select count(*) from t1;
CREATE MATERIALIZED VIEW
-- Query the materialized view result.
openGauss=# SELECT * FROM mv;
count
-------
2
(1 row)
-- Insert data into the base table in the materialized view.
openGauss=# INSERT INTO t1 VALUES(3, 3);
INSERT 0 1
-- Completely refresh the complete-refresh materialized view.
openGauss=# REFRESH MATERIALIZED VIEW mv;
REFRESH MATERIALIZED VIEW
-- Query the materialized view result.
openGauss=# SELECT * FROM mv;
count
-------
3
(1 row)
-- Delete the materialized view.
openGauss=# DROP MATERIALIZED VIEW mv;
DROP MATERIALIZED VIEW Parent topic: Complete-refresh Materialized View
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.