summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAlvaro Herrera2014-12-19 18:00:45 +0000
committerAlvaro Herrera2014-12-19 18:00:45 +0000
commit0ee98d1cbf1cd3b888633b2ee90e0001889c12b9 (patch)
treeedf24dba8ab9d9a08e4a5b138de36b07f5e4c0ee /src/test
parent5c805d0a813e6c611485bfc9bde9d2a10d1800e5 (diff)
pg_event_trigger_dropped_objects: add behavior flags
Add "normal" and "original" flags as output columns to the pg_event_trigger_dropped_objects() function. With this it's possible to distinguish which objects, among those listed, need to be explicitely referenced when trying to replicate a deletion. This is necessary so that the list of objects can be pruned to the minimum necessary to replicate the DROP command in a remote server that might have slightly different schema (for instance, TOAST tables and constraints with different names and such.) Catalog version bumped due to change of function definition. Reviewed by: Abhijit Menon-Sen, Stephen Frost, Heikki Linnakangas, Robert Haas.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/event_trigger.out40
-rw-r--r--src/test/regress/sql/event_trigger.sql30
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/regress/expected/event_trigger.out b/src/test/regress/expected/event_trigger.out
index 5934cf74b19..72e1660d6b9 100644
--- a/src/test/regress/expected/event_trigger.out
+++ b/src/test/regress/expected/event_trigger.out
@@ -294,6 +294,46 @@ SELECT * FROM dropped_objects WHERE type = 'schema';
DROP ROLE regression_bob;
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
DROP EVENT TRIGGER undroppable;
+CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
+ RETURNS event_trigger
+ LANGUAGE plpgsql
+AS $$
+DECLARE r record;
+BEGIN
+ FOR r IN SELECT * from pg_event_trigger_dropped_objects()
+ LOOP
+ IF NOT r.normal AND NOT r.original THEN
+ CONTINUE;
+ END IF;
+ RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
+ r.original, r.normal, r.object_type, r.object_identity;
+ END LOOP;
+END; $$;
+CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
+ EXECUTE PROCEDURE event_trigger_report_dropped();
+CREATE SCHEMA evttrig
+ CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
+ CREATE INDEX one_idx ON one (col_b)
+ CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
+ALTER TABLE evttrig.two DROP COLUMN col_c;
+NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c
+NOTICE: NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two
+ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
+NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b
+ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
+NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one
+DROP INDEX evttrig.one_idx;
+NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx
+DROP SCHEMA evttrig CASCADE;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to table evttrig.one
+drop cascades to table evttrig.two
+NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig
+NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one
+NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq
+NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a
+NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two
+DROP EVENT TRIGGER regress_event_trigger_report_dropped;
-- only allowed from within an event trigger function, should fail
select pg_event_trigger_table_rewrite_oid();
ERROR: pg_event_trigger_table_rewrite_oid() can only be called in a table_rewrite event trigger function
diff --git a/src/test/regress/sql/event_trigger.sql b/src/test/regress/sql/event_trigger.sql
index 02b93c9e1f0..7987fde50b9 100644
--- a/src/test/regress/sql/event_trigger.sql
+++ b/src/test/regress/sql/event_trigger.sql
@@ -207,6 +207,36 @@ DROP ROLE regression_bob;
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
DROP EVENT TRIGGER undroppable;
+CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
+ RETURNS event_trigger
+ LANGUAGE plpgsql
+AS $$
+DECLARE r record;
+BEGIN
+ FOR r IN SELECT * from pg_event_trigger_dropped_objects()
+ LOOP
+ IF NOT r.normal AND NOT r.original THEN
+ CONTINUE;
+ END IF;
+ RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
+ r.original, r.normal, r.object_type, r.object_identity;
+ END LOOP;
+END; $$;
+CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
+ EXECUTE PROCEDURE event_trigger_report_dropped();
+CREATE SCHEMA evttrig
+ CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
+ CREATE INDEX one_idx ON one (col_b)
+ CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
+
+ALTER TABLE evttrig.two DROP COLUMN col_c;
+ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
+ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
+DROP INDEX evttrig.one_idx;
+DROP SCHEMA evttrig CASCADE;
+
+DROP EVENT TRIGGER regress_event_trigger_report_dropped;
+
-- only allowed from within an event trigger function, should fail
select pg_event_trigger_table_rewrite_oid();