From the manual
CREATE MATERIALIZED VIEW is similar to CREATE TABLE AS, except that it also remembers the query used to initialize the view, so that it can be refreshed later upon demand.
As I understand refreshing a materialized view should have the same effect as recreate view as
. But it is not what happens here.
Create a table with a single column
drop table if exists t cascade;
create table t (a int);
insert into t (a) values (1);
Create the materialized view
create materialized view mat_view_t as
select * from t ;
select * from mat_view_t;
a
---
1
Now a column is added to the source table
alter table t add column b int;
\d t
Table "public.t"
Column | Type | Modifiers
--------+---------+-----------
a | integer |
b | integer |
And then the materialized view is refreshed
refresh materialized view mat_view_t;
select * from mat_view_t;
a
---
1
\d mat_view_t
Materialized view "public.mat_view_t"
Column | Type | Modifiers
--------+---------+-----------
a | integer |
Where is the new column? Is it the expected behaviour? If it is then I think the manual is misleading.