Prohibit transition tables on views and foreign tables.
authorRobert Haas <rhaas@postgresql.org>
Wed, 10 May 2017 03:34:02 +0000 (23:34 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 10 May 2017 03:34:02 +0000 (23:34 -0400)
Thomas Munro, per off-list report from Prabhat Sabu.  Changes
to the message wording for consistency with the existing
relkind check for partitioned tables by me.

Discussion: http://postgr.es/m/CAEepm=2xJFFpGM+N=gpWx-9Nft2q1oaFZX07_y23AHCrJQLt0g@mail.gmail.com

src/backend/commands/trigger.c
src/test/regress/expected/foreign_data.out
src/test/regress/expected/triggers.out
src/test/regress/sql/foreign_data.sql
src/test/regress/sql/triggers.sql

index c0511639db027e3be00520fd7f5e839d9ff5f590..819395a9678ae88352a1d7bc790aa21a3675b97a 100644 (file)
@@ -361,6 +361,20 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
                                RelationGetRelationName(rel)),
                     errdetail("Triggers on partitioned tables cannot have transition tables.")));
 
+           if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+               ereport(ERROR,
+                       (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                        errmsg("\"%s\" is a foreign table",
+                               RelationGetRelationName(rel)),
+                    errdetail("Triggers on foreign tables cannot have transition tables.")));
+
+           if (rel->rd_rel->relkind == RELKIND_VIEW)
+               ereport(ERROR,
+                       (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                        errmsg("\"%s\" is a view",
+                               RelationGetRelationName(rel)),
+                    errdetail("Triggers on views cannot have transition tables.")));
+
            if (stmt->timing != TRIGGER_TYPE_AFTER)
                ereport(ERROR,
                        (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
index af327d030d92aab1c2dbd6d459c874f2f2575e9f..6a1f22ebeba10f35c0cf679cbfdfe61a868aa3a4 100644 (file)
@@ -1269,6 +1269,13 @@ CREATE TRIGGER trigtest_after_stmt AFTER INSERT OR UPDATE OR DELETE
 ON foreign_schema.foreign_table_1
 FOR EACH STATEMENT
 EXECUTE PROCEDURE dummy_trigger();
+CREATE TRIGGER trigtest_after_stmt_tt AFTER INSERT OR UPDATE OR DELETE -- ERROR
+ON foreign_schema.foreign_table_1
+REFERENCING NEW TABLE AS new_table
+FOR EACH STATEMENT
+EXECUTE PROCEDURE dummy_trigger();
+ERROR:  "foreign_table_1" is a foreign table
+DETAIL:  Triggers on foreign tables cannot have transition tables.
 CREATE TRIGGER trigtest_before_row BEFORE INSERT OR UPDATE OR DELETE
 ON foreign_schema.foreign_table_1
 FOR EACH ROW
index 10a301310b47a998fd6c20158316f90d7173cf6c..c300449f3aaa978537db532dd5b6b9f8a046a9d0 100644 (file)
@@ -1785,9 +1785,24 @@ drop trigger my_trigger on my_table_42;
 create trigger my_trigger after update on my_table_42 referencing old table as old_table
    for each statement execute procedure my_trigger_function();
 drop trigger my_trigger on my_table_42;
+drop function my_trigger_function();
 drop table my_table_42;
 drop table my_table;
 --
+-- Verify that triggers with transition tables are not allowed on
+-- views
+--
+create table my_table (i int);
+create view my_view as select * from my_table;
+create function my_trigger_function() returns trigger as $$ begin end; $$ language plpgsql;
+create trigger my_trigger after update on my_view referencing old table as old_table
+   for each statement execute procedure my_trigger_function();
+ERROR:  "my_view" is a view
+DETAIL:  Triggers on views cannot have transition tables.
+drop function my_trigger_function();
+drop view my_view;
+drop table my_table;
+--
 -- Verify that per-statement triggers are fired for partitioned tables
 --
 create table parted_stmt_trig (a int) partition by list (a);
index ba528b5d36be895b0c0bb983d16732263931e867..49255e309c13a14f262dbcbfcbc9a4312ae70edb 100644 (file)
@@ -527,6 +527,12 @@ ON foreign_schema.foreign_table_1
 FOR EACH STATEMENT
 EXECUTE PROCEDURE dummy_trigger();
 
+CREATE TRIGGER trigtest_after_stmt_tt AFTER INSERT OR UPDATE OR DELETE -- ERROR
+ON foreign_schema.foreign_table_1
+REFERENCING NEW TABLE AS new_table
+FOR EACH STATEMENT
+EXECUTE PROCEDURE dummy_trigger();
+
 CREATE TRIGGER trigtest_before_row BEFORE INSERT OR UPDATE OR DELETE
 ON foreign_schema.foreign_table_1
 FOR EACH ROW
index 84b5ada5544e4b4283f14b4bddd938d01980a4c1..e5dbcaeea36f9df9edf68a6d64e4fcf71393a64f 100644 (file)
@@ -1261,9 +1261,24 @@ drop trigger my_trigger on my_table_42;
 create trigger my_trigger after update on my_table_42 referencing old table as old_table
    for each statement execute procedure my_trigger_function();
 drop trigger my_trigger on my_table_42;
+drop function my_trigger_function();
 drop table my_table_42;
 drop table my_table;
 
+--
+-- Verify that triggers with transition tables are not allowed on
+-- views
+--
+
+create table my_table (i int);
+create view my_view as select * from my_table;
+create function my_trigger_function() returns trigger as $$ begin end; $$ language plpgsql;
+create trigger my_trigger after update on my_view referencing old table as old_table
+   for each statement execute procedure my_trigger_function();
+drop function my_trigger_function();
+drop view my_view;
+drop table my_table;
+
 --
 -- Verify that per-statement triggers are fired for partitioned tables
 --