REFRESH MATERIALIZED VIEW

A DDL command to update a materialized view

REFRESH MATERIALIZED VIEW is a DDL command to update a materialized view.

REFRESH MATERIALIZED VIEW was added in PostgreSQL 9.3.

Change history

Examples

Basic usage example for REFRESH 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=# INSERT INTO foo VALUES(2, 'baz');
INSERT 0 1

postgres=# SELECT * FROM bar;
 id | val 
----+-----
  1 | bar
(1 row)

postgres=# REFRESH MATERIALIZED VIEW bar;
REFRESH MATERIALIZED VIEW

postgres=# SELECT * FROM bar;
 id | val 
----+-----
  1 | bar
  2 | baz
(2 rows)

Categories

DDL, SQL command

See also

CREATE MATERIALIZED VIEW, DROP MATERIALIZED VIEW