Skip to content

Commit 02af785

Browse files
committed
Allow a rule on partitioned table to be renamed.
Commit f0e4475 should have updated this code, but did not. Amit Langote Discussion: http://postgr.es/m/52d9c443-ec78-5c8a-7a77-0f34aad12b82@lab.ntt.co.jp
1 parent 6599c9a commit 02af785

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/backend/rewrite/rewriteDefine.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,9 @@ RangeVarCallbackForRenameRule(const RangeVar *rv, Oid relid, Oid oldrelid,
900900
form = (Form_pg_class) GETSTRUCT(tuple);
901901

902902
/* only tables and views can have rules */
903-
if (form->relkind != RELKIND_RELATION && form->relkind != RELKIND_VIEW)
903+
if (form->relkind != RELKIND_RELATION &&
904+
form->relkind != RELKIND_VIEW &&
905+
form->relkind != RELKIND_PARTITIONED_TABLE)
904906
ereport(ERROR,
905907
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
906908
errmsg("\"%s\" is not a table or view", rv->relname)));

src/test/regress/expected/rules.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,3 +3216,10 @@ SELECT pg_get_function_arg_default('pg_class'::regclass, 0);
32163216

32173217
(1 row)
32183218

3219+
-- test rename for a rule defined on a partitioned table
3220+
CREATE TABLE parted_table (a int) PARTITION BY LIST (a);
3221+
CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1);
3222+
CREATE RULE parted_table_insert AS ON INSERT to parted_table
3223+
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
3224+
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
3225+
DROP TABLE parted_table;

src/test/regress/sql/rules.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,11 @@ SELECT pg_get_function_identity_arguments(0);
11581158
SELECT pg_get_function_result(0);
11591159
SELECT pg_get_function_arg_default(0, 0);
11601160
SELECT pg_get_function_arg_default('pg_class'::regclass, 0);
1161+
1162+
-- test rename for a rule defined on a partitioned table
1163+
CREATE TABLE parted_table (a int) PARTITION BY LIST (a);
1164+
CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1);
1165+
CREATE RULE parted_table_insert AS ON INSERT to parted_table
1166+
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
1167+
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
1168+
DROP TABLE parted_table;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy