@@ -3112,6 +3112,57 @@ drop trigger child_row_trig on child;
31123112alter table parent attach partition child for values in ('AAA');
31133113drop table child, parent;
31143114--
3115+ -- Verify access of transition tables with UPDATE triggers and tuples
3116+ -- moved across partitions.
3117+ --
3118+ create or replace function dump_update_new() returns trigger language plpgsql as
3119+ $$
3120+ begin
3121+ raise notice 'trigger = %, new table = %', TG_NAME,
3122+ (select string_agg(new_table::text, ', ' order by a) from new_table);
3123+ return null;
3124+ end;
3125+ $$;
3126+ /
3127+ create or replace function dump_update_old() returns trigger language plpgsql as
3128+ $$
3129+ begin
3130+ raise notice 'trigger = %, old table = %', TG_NAME,
3131+ (select string_agg(old_table::text, ', ' order by a) from old_table);
3132+ return null;
3133+ end;
3134+ $$;
3135+ /
3136+ create table trans_tab_parent (a text) partition by list (a);
3137+ create table trans_tab_child1 partition of trans_tab_parent for values in ('AAA1', 'AAA2');
3138+ create table trans_tab_child2 partition of trans_tab_parent for values in ('BBB1', 'BBB2');
3139+ create trigger trans_tab_parent_update_trig
3140+ after update on trans_tab_parent referencing old table as old_table
3141+ for each statement execute procedure dump_update_old();
3142+ create trigger trans_tab_parent_insert_trig
3143+ after insert on trans_tab_parent referencing new table as new_table
3144+ for each statement execute procedure dump_insert();
3145+ create trigger trans_tab_parent_delete_trig
3146+ after delete on trans_tab_parent referencing old table as old_table
3147+ for each statement execute procedure dump_delete();
3148+ insert into trans_tab_parent values ('AAA1'), ('BBB1');
3149+ NOTICE: trigger = trans_tab_parent_insert_trig, new table = (AAA1), (BBB1)
3150+ -- should not trigger access to new table when moving across partitions.
3151+ update trans_tab_parent set a = 'BBB2' where a = 'AAA1';
3152+ NOTICE: trigger = trans_tab_parent_update_trig, old table = (AAA1)
3153+ drop trigger trans_tab_parent_update_trig on trans_tab_parent;
3154+ create trigger trans_tab_parent_update_trig
3155+ after update on trans_tab_parent referencing new table as new_table
3156+ for each statement execute procedure dump_update_new();
3157+ -- should not trigger access to old table when moving across partitions.
3158+ update trans_tab_parent set a = 'AAA2' where a = 'BBB1';
3159+ NOTICE: trigger = trans_tab_parent_update_trig, new table = (AAA2)
3160+ delete from trans_tab_parent;
3161+ NOTICE: trigger = trans_tab_parent_delete_trig, old table = (AAA2), (BBB2)
3162+ -- clean up
3163+ drop table trans_tab_parent, trans_tab_child1, trans_tab_child2;
3164+ drop function dump_update_new, dump_update_old;
3165+ --
31153166-- Verify behavior of statement triggers on (non-partition)
31163167-- inheritance hierarchy with transition tables; similar to the
31173168-- partition case, except there is no rerouting on insertion and child
0 commit comments