ALTER MATERIALIZED VIEW
是一个 DDL 命令,用于修改物化视图的定义。
ALTER MATERIALIZED VIEW
添加于 PostgreSQL 9.3。
更改历史
- PostgreSQL 14
ALTER MATERIALIZED VIEW ... OWNER TO CURRENT_ROLE
语法已添加 (提交 45b98057)
- PostgreSQL 13
- PostgreSQL 9.6
DEPENDS ON EXTENSION
语法已添加 (提交 f2fcad27)
- PostgreSQL 9.4
ALTER MATERIALIZED VIEW ALL IN TABLESPACE ... SET TABLESPACE ...
语法已添加 (提交 d9b2bc45)
- PostgreSQL 9.3
- 已添加 (提交 3bf3ab8c)
示例
ALTER MATERIALIZED VIEW
的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT); CREATE TABLE postgres=# INSERT INTO foo VALUES(1, 'bar'); INSERT 0 1 postgres=# CREATE MATERIALIZED VIEW bar AS SELECT * FROM foo; SELECT 1 postgres=# \d bar Materialized view "public.bar" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- id | integer | | | val | text | | | postgres=# ALTER MATERIALIZED VIEW bar RENAME val TO foo_val; ALTER MATERIALIZED VIEW postgres=# \d bar Materialized view "public.bar" Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- id | integer | | | foo_val | text | | |
参考文献
- PostgreSQL 文档: ALTER MATERIALIZED VIEW