Updated on 2024-05-07 GMT+08:00

ALTER MATERIALIZED VIEW

Description

Changes 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 TMATERIALIZED VIEW permission.
  • The materialized view structure cannot be modified.

Syntax

  • Change the owner of a 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. It must comply with the naming convention.

  • column_name

    Specifies the name of a new or existing column.

    Value range: a string. It must comply with the naming convention.

  • 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.
gaussdb=# CREATE TABLE my_table (c1 int, c2 int)
WITH(STORAGE_TYPE=ASTORE);

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

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

-- Delete the complete-refresh materialized view.
gaussdb=# DROP MATERIALIZED VIEW bar;

-- Delete the my_table table.
gaussdb=# DROP TABLE my_table;