From c31d5ec9ab67b8e8c686152e268b30d8fed3e5d1 Mon Sep 17 00:00:00 2001 From: qmitchell-aa <139587172+qmitchell-aa@users.noreply.github.com> Date: Wed, 12 Mar 2025 09:15:29 -0400 Subject: [PATCH 1/2] README - detail on renaming IMMV + fix typo in drop IMMV --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0c9247..7d14bf9 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM An IMMV can be dropped using the `DROP TABLE` command. Once an IMMV is dropped, its entry is automatically removed from the `pg_ivm_immv` catalog. ```sql -test=# DROP TABLE immv; +test=# DROP TABLE immv_agg; DROP TABLE test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM pgivm.pg_ivm_immv; @@ -316,6 +316,27 @@ test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM (1 row) ``` +### Renaming an IMMV + +An IMMV can be renamed using the `ALTER TABLE` command. Once an IMMV is renamed, its entry is automatically renamed in the `pg_ivm_immv` catalog. + +```sql +test=# ALTER TABLE immv_agg RENAME TO immv_agg2; +ALTER TABLE + +test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM pgivm.pg_ivm_immv; + immv | immv_def +-----------+-------------------------------------------- + immv_agg2 | SELECT pgbench_accounts.bid, + + | count(*) AS count, + + | sum(pgbench_accounts.abalance) AS sum,+ + | avg(pgbench_accounts.abalance) AS avg + + | FROM (pgbench_accounts + + | JOIN pgbench_branches USING (bid)) + + | GROUP BY pgbench_accounts.bid +(1 row) +``` + ## `pg_dump` and `pg_upgrade` After restoring data from a `pg_dump` backup or upgrading `PostgreSQL` using `pg_upgrade`, all IMMVs must be manually dropped and recreated. From deb2652335189b3c7a6115f3269b5ce39e0497c9 Mon Sep 17 00:00:00 2001 From: Yugo Nagata Date: Mon, 26 May 2025 15:52:31 +0900 Subject: [PATCH 2/2] Some fix - Revert a typo fix on IMMV deletion For consistency of the documents, dropped IMMV should be immv rather than immv_agg - Remove the description about the entry modification in the catalog Actually, the catalog entry doesn't not change when an IMMV is renamed since it just references IMMV's Oids. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d14bf9..8b0c946 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM An IMMV can be dropped using the `DROP TABLE` command. Once an IMMV is dropped, its entry is automatically removed from the `pg_ivm_immv` catalog. ```sql -test=# DROP TABLE immv_agg; +test=# DROP TABLE immv DROP TABLE test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM pgivm.pg_ivm_immv; @@ -318,7 +318,7 @@ test=# SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid) AS immv_def FROM ### Renaming an IMMV -An IMMV can be renamed using the `ALTER TABLE` command. Once an IMMV is renamed, its entry is automatically renamed in the `pg_ivm_immv` catalog. +An IMMV can be renamed using the `ALTER TABLE` command. ```sql test=# ALTER TABLE immv_agg RENAME TO immv_agg2;