Re: [HACKERS] RENAME RULE doesn't work with partitioned tables

2017-04-11 Thread Amit Langote
On 2017/04/12 2:20, Robert Haas wrote:
> On Tue, Apr 11, 2017 at 5:54 AM, Amit Langote
>  wrote:
>> Just noticed that RangeVarCallbackForRenameRule() was not updated to
>> handle partitioned tables, causing the following bug:
>>
>> create table parted_table (a int) partition by list (a);
>> create table part partition of parted_table for values in (1);
>> create rule parted_table_insert as on insert to parted_table
>>   do instead insert into part values (new.*);
>> alter rule parted_table_insert on parted_table
>>   rename to parted_table_insert_redirect;
>> -- ERROR:  "parted_table" is not a table or view
>>
>> Attached fixes this and adds a test.  Added to open items list.
> 
> Committed.

Thanks.

Regards,
Amit




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] RENAME RULE doesn't work with partitioned tables

2017-04-11 Thread Robert Haas
On Tue, Apr 11, 2017 at 5:54 AM, Amit Langote
 wrote:
> Just noticed that RangeVarCallbackForRenameRule() was not updated to
> handle partitioned tables, causing the following bug:
>
> create table parted_table (a int) partition by list (a);
> create table part partition of parted_table for values in (1);
> create rule parted_table_insert as on insert to parted_table
>   do instead insert into part values (new.*);
> alter rule parted_table_insert on parted_table
>   rename to parted_table_insert_redirect;
> -- ERROR:  "parted_table" is not a table or view
>
> Attached fixes this and adds a test.  Added to open items list.

Committed.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] RENAME RULE doesn't work with partitioned tables

2017-04-11 Thread Amit Langote
Just noticed that RangeVarCallbackForRenameRule() was not updated to
handle partitioned tables, causing the following bug:

create table parted_table (a int) partition by list (a);
create table part partition of parted_table for values in (1);
create rule parted_table_insert as on insert to parted_table
  do instead insert into part values (new.*);
alter rule parted_table_insert on parted_table
  rename to parted_table_insert_redirect;
-- ERROR:  "parted_table" is not a table or view

Attached fixes this and adds a test.  Added to open items list.

Thanks,
Amit
>From 1ee94584648e15b8fa599f642eff871e8d8e4780 Mon Sep 17 00:00:00 2001
From: amit 
Date: Tue, 11 Apr 2017 18:43:41 +0900
Subject: [PATCH] Fix RENAME RULE to consider partitioned tables

RangeVarCallbackForRenameRule wasn't updated to reflect that
partitioned tables have rules too.
---
 src/backend/rewrite/rewriteDefine.c | 4 +++-
 src/test/regress/expected/rules.out | 7 +++
 src/test/regress/sql/rules.sql  | 8 
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 86d588bba5..df32f2c3ae 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -900,7 +900,9 @@ RangeVarCallbackForRenameRule(const RangeVar *rv, Oid relid, Oid oldrelid,
 	form = (Form_pg_class) GETSTRUCT(tuple);
 
 	/* only tables and views can have rules */
-	if (form->relkind != RELKIND_RELATION && form->relkind != RELKIND_VIEW)
+	if (form->relkind != RELKIND_RELATION &&
+		form->relkind != RELKIND_VIEW &&
+		form->relkind != RELKIND_PARTITIONED_TABLE)
 		ereport(ERROR,
 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
  errmsg("\"%s\" is not a table or view", rv->relname)));
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index cba82bb114..f55c8c47eb 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -3216,3 +3216,10 @@ SELECT pg_get_function_arg_default('pg_class'::regclass, 0);
  
 (1 row)
 
+-- test rename for a rule defined on a partitioned table
+CREATE TABLE parted_table (a int) PARTITION BY LIST (a);
+CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1);
+CREATE RULE parted_table_insert AS ON INSERT to parted_table
+DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
+ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
+DROP TABLE parted_table;
diff --git a/src/test/regress/sql/rules.sql b/src/test/regress/sql/rules.sql
index dcff0de2a5..d4a61813e4 100644
--- a/src/test/regress/sql/rules.sql
+++ b/src/test/regress/sql/rules.sql
@@ -1158,3 +1158,11 @@ SELECT pg_get_function_identity_arguments(0);
 SELECT pg_get_function_result(0);
 SELECT pg_get_function_arg_default(0, 0);
 SELECT pg_get_function_arg_default('pg_class'::regclass, 0);
+
+-- test rename for a rule defined on a partitioned table
+CREATE TABLE parted_table (a int) PARTITION BY LIST (a);
+CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1);
+CREATE RULE parted_table_insert AS ON INSERT to parted_table
+DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
+ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
+DROP TABLE parted_table;
-- 
2.11.0


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers