create table parent (a text, b int) partition by list (a);
create table child1 partition of parent for values in ('AAA');

create extension postgres_fdw;
create server loopback foreign data wrapper postgres_fdw options (dbname 'postgres');
create user mapping for current_user server loopback;
create table child2 (a text, b int);
create foreign table child2_foreign (a text, b int) server loopback options (table_name 'child2');

alter table parent attach partition child2_foreign for values in ('BBB');

create or replace function dump_transition_tables() returns trigger language plpgsql as
$$
  begin
    raise notice 'trigger = %, old table = %, new table = %',
                 TG_NAME,
                 (select string_agg(old_table::text, ', ' order by a) from old_table),
                 (select string_agg(new_table::text, ', ' order by a) from new_table);
    return null;
  end;
$$;

create trigger parent_stmt_trig
  after insert or update or delete on parent
  referencing old table as old_table new table as new_table
  for each statement
  execute procedure dump_transition_tables();

-- inserting into parent fails because FDWs don't support insert routing yet
insert into parent values ('AAA', 42), ('BBB', 42);

-- ... so do that for child1, but insert into the foreign partition directly:
insert into parent values ('AAA', 42);
insert into child2_foreign values ('BBB', 42);

-- updating parent captures tuples only from child1
update parent set b = b;

-- deleting from parent captures tuples only from child1
delete from parent;
