pg_ivm/expected/create_immv.out
thoshiai 51a944b388 Add refresh_immv() function
refresh_immv(immv_name, with_data) is a function to refresh IMMV like
 REFRESH MATERIALIZED VIEW command. It has two argument.
immv_name is incrementally maintainable materialized view's name, and
with_data is an option that is corresponding to the WITH [NO] DATA option.
When with_data is set false, the IMMV gets unpopulated.

One of differences between IMMVs unpopulated by this function and
normal materialized views unpopulated by REFRESH ... WITH NO DATA
is that such IMMVs can be referenced by SELECT but return no rows,
while unpopulated materialized views are not scanable.

The behaviour may be changed in future to raise an error when unpopulated
an IMMV is scanned.
2022-06-16 03:06:47 +09:00

44 lines
1 KiB
Text

CREATE TABLE t (i int PRIMARY KEY);
INSERT INTO t SELECT generate_series(1, 100);
SELECT create_immv('mv', 'SELECT * FROM t');
NOTICE: created index "mv_index" on immv "mv"
create_immv
-------------
100
(1 row)
SELECT create_immv(' mv2 ( x ) ', 'SELECT * FROM t WHERE i%2 = 0');
NOTICE: created index "mv2_index" on immv "mv2"
create_immv
-------------
50
(1 row)
SELECT create_immv('mv3', 'WITH d AS (DELETE FROM t RETURNING NULL) SELECT * FROM t');
ERROR: materialized views must not use data-modifying statements in WITH
SELECT immvrelid FROM pg_ivm_immv ORDER BY 1;
immvrelid
-----------
mv
mv2
(2 rows)
DROP TABLE t;
ERROR: cannot drop table t because other objects depend on it
DETAIL: table mv depends on table t
table mv2 depends on table t
HINT: Use DROP ... CASCADE to drop the dependent objects too.
DROP TABLE mv;
SELECT immvrelid FROM pg_ivm_immv ORDER BY 1;
immvrelid
-----------
mv2
(1 row)
DROP TABLE mv2;
SELECT immvrelid FROM pg_ivm_immv ORDER BY 1;
immvrelid
-----------
(0 rows)
DROP TABLE t;