user6295635 user6295635 - 8 months ago 31
SQL Question

Calling a materialized view from another materialized view in Postgres

Is it possible to create a view, called first_view and in another view called second_view the first one is called? This is the original question.

This is the first view:

AS SELECT atable.variable_one, btable.another_variable, ctable.variable_x
FROM a atable, b btable, c ctable

So that f(a,b,c) view can be called in f(ALL) which is f(a,b,c) including f(m) with aggregate functions.


The answer is so simply that I assume that I do not understand your question properly:

Just use the first MVIEW the same way you use any other table or view in the second MVIEW:

create materialized view first_view
select a.column_one, b.column_two, c.column_three
from table_a a 
   join table_b b on = b.aid
   join table_c c on =;

create materialized view second_view
select x.some_column, f.*
from other_table x
   join first_view f on = f.column_one;