Skip to content

Commit 9e6104c

Browse files
committed
Prohibit transition tables on views and foreign tables.
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
1 parent 29fd3d9 commit 9e6104c

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

src/backend/commands/trigger.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,20 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
361361
RelationGetRelationName(rel)),
362362
errdetail("Triggers on partitioned tables cannot have transition tables.")));
363363

364+
if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
365+
ereport(ERROR,
366+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
367+
errmsg("\"%s\" is a foreign table",
368+
RelationGetRelationName(rel)),
369+
errdetail("Triggers on foreign tables cannot have transition tables.")));
370+
371+
if (rel->rd_rel->relkind == RELKIND_VIEW)
372+
ereport(ERROR,
373+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
374+
errmsg("\"%s\" is a view",
375+
RelationGetRelationName(rel)),
376+
errdetail("Triggers on views cannot have transition tables.")));
377+
364378
if (stmt->timing != TRIGGER_TYPE_AFTER)
365379
ereport(ERROR,
366380
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),

src/test/regress/expected/foreign_data.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,13 @@ CREATE TRIGGER trigtest_after_stmt AFTER INSERT OR UPDATE OR DELETE
12691269
ON foreign_schema.foreign_table_1
12701270
FOR EACH STATEMENT
12711271
EXECUTE PROCEDURE dummy_trigger();
1272+
CREATE TRIGGER trigtest_after_stmt_tt AFTER INSERT OR UPDATE OR DELETE -- ERROR
1273+
ON foreign_schema.foreign_table_1
1274+
REFERENCING NEW TABLE AS new_table
1275+
FOR EACH STATEMENT
1276+
EXECUTE PROCEDURE dummy_trigger();
1277+
ERROR: "foreign_table_1" is a foreign table
1278+
DETAIL: Triggers on foreign tables cannot have transition tables.
12721279
CREATE TRIGGER trigtest_before_row BEFORE INSERT OR UPDATE OR DELETE
12731280
ON foreign_schema.foreign_table_1
12741281
FOR EACH ROW

src/test/regress/expected/triggers.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,9 +1785,24 @@ drop trigger my_trigger on my_table_42;
17851785
create trigger my_trigger after update on my_table_42 referencing old table as old_table
17861786
for each statement execute procedure my_trigger_function();
17871787
drop trigger my_trigger on my_table_42;
1788+
drop function my_trigger_function();
17881789
drop table my_table_42;
17891790
drop table my_table;
17901791
--
1792+
-- Verify that triggers with transition tables are not allowed on
1793+
-- views
1794+
--
1795+
create table my_table (i int);
1796+
create view my_view as select * from my_table;
1797+
create function my_trigger_function() returns trigger as $$ begin end; $$ language plpgsql;
1798+
create trigger my_trigger after update on my_view referencing old table as old_table
1799+
for each statement execute procedure my_trigger_function();
1800+
ERROR: "my_view" is a view
1801+
DETAIL: Triggers on views cannot have transition tables.
1802+
drop function my_trigger_function();
1803+
drop view my_view;
1804+
drop table my_table;
1805+
--
17911806
-- Verify that per-statement triggers are fired for partitioned tables
17921807
--
17931808
create table parted_stmt_trig (a int) partition by list (a);

src/test/regress/sql/foreign_data.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ ON foreign_schema.foreign_table_1
527527
FOR EACH STATEMENT
528528
EXECUTE PROCEDURE dummy_trigger();
529529

530+
CREATE TRIGGER trigtest_after_stmt_tt AFTER INSERT OR UPDATE OR DELETE -- ERROR
531+
ON foreign_schema.foreign_table_1
532+
REFERENCING NEW TABLE AS new_table
533+
FOR EACH STATEMENT
534+
EXECUTE PROCEDURE dummy_trigger();
535+
530536
CREATE TRIGGER trigtest_before_row BEFORE INSERT OR UPDATE OR DELETE
531537
ON foreign_schema.foreign_table_1
532538
FOR EACH ROW

src/test/regress/sql/triggers.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,24 @@ drop trigger my_trigger on my_table_42;
12611261
create trigger my_trigger after update on my_table_42 referencing old table as old_table
12621262
for each statement execute procedure my_trigger_function();
12631263
drop trigger my_trigger on my_table_42;
1264+
drop function my_trigger_function();
12641265
drop table my_table_42;
12651266
drop table my_table;
12661267

1268+
--
1269+
-- Verify that triggers with transition tables are not allowed on
1270+
-- views
1271+
--
1272+
1273+
create table my_table (i int);
1274+
create view my_view as select * from my_table;
1275+
create function my_trigger_function() returns trigger as $$ begin end; $$ language plpgsql;
1276+
create trigger my_trigger after update on my_view referencing old table as old_table
1277+
for each statement execute procedure my_trigger_function();
1278+
drop function my_trigger_function();
1279+
drop view my_view;
1280+
drop table my_table;
1281+
12671282
--
12681283
-- Verify that per-statement triggers are fired for partitioned tables
12691284
--

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