Updated on 2025-02-27 GMT+08:00

ALTER MATERIALIZED VIEW

Description

Alters multiple auxiliary attributes of an existing materialized view.

Statements and actions that can be used for ALTER MATERIALIZED VIEW are a subset of ALTER TABLE and have the same meaning when used for materialized views. For details, see ALTER TABLE.

Precautions

  • Only the owner of a materialized view or a system administrator has the ALTER MATERIALIZED VIEW permission.
  • The materialized view structure cannot be modified.

Syntax

  • Alter the owner of the materialized view.
    ALTER MATERIALIZED VIEW [ IF EXISTS ] mv_name
        OWNER TO new_owner;
  • Modify the column of a materialized view.
    ALTER MATERIALIZED VIEW [ IF EXISTS ] mv_name
        RENAME [ COLUMN ] column_name TO new_column_name;
  • Rename a materialized view.
    ALTER MATERIALIZED VIEW [ IF EXISTS ] mv_name
     
        RENAME TO new_name;

Parameters

  • mv_name

    Specifies the name of an existing materialized view, which can be schema-qualified.

    Value range: a string that complies with the Identifier Naming Conventions.

  • column_name

    Specifies the name of a new or existing column.

    Value range: a string that complies with the Identifier Naming Conventions.

  • new_column_name

    Specifies the new name of an existing column.

  • new_owner

    Specifies the username of the new owner of a materialized view.

  • new_name

    Specifies the new name of a materialized view.

Examples

-- Create a table.
openGauss=# CREATE TABLE my_table (c1 int, c2 int) WITH(STORAGE_TYPE=ASTORE);

-- Create a complete-refresh materialized view.
openGauss=# CREATE MATERIALIZED VIEW foo AS SELECT * FROM my_table;

-- Rename the materialized view foo to bar.
openGauss=# ALTER MATERIALIZED VIEW foo RENAME TO bar;

-- Drop a complete-refresh materialized view.
openGauss=# DROP MATERIALIZED VIEW bar;

-- Drop the my_table table.
openGauss=# DROP TABLE my_table;