A “materialized view” is a database object which stores the result of a precalculated database query and makes it easy to refresh this result as needed.
After creating the materalized view, when data is added, removed and updated to the tables in the materalized view, the data in the materalized view does not change.
To update the changed data, it is necessary to update the materalized view with the “refresh materalized view” command.
Let’s do an example.
1 2 3 4 5 6 7 8 9 | INSERT INTO public.film( film_id, title,language_id) VALUES (1002, 'ZORRO ARK',1); INSERT INTO public.actor( actor_id, first_name, last_name) VALUES (202, 'Ahmet', 'Kara'); INSERT INTO public.film_actor( actor_id, film_id) VALUES (202, 1002); |
After adding our data, when we select the Materialized view called “actorfilm”, we see that the same number is returned and there is no change.
After running the refresh command, we see at the bottom right that our record has increased by one.