/* :%s/user1/your_username/g */
/* connect to foreign server */
\c postgres user1 localhost 5433

create table ftable(val int);
insert into ftable select i from generate_series(20, 25) i;

/* connect to base server */
\c postgres user1 localhost 5432

create extension postgres_fdw;

create table parent(val int);
create table child1() inherits (parent);

insert into parent select i from generate_series(0, 10) i;
insert into child1 select i from generate_series(10, 20) i;

/* should be all ok */
update parent set val = val + 1;

/* now we add fdw table */
create server fserv
	foreign data wrapper postgres_fdw
	options (dbname 'postgres', host '127.0.0.1', port '5433');
create user mapping for user1 server fserv options (user 'user1');
import foreign schema public limit to (ftable) from server fserv into public;
alter table ftable inherit parent;

/* should be all ok */
update parent set val = val + 1;

/* create before row trigger on fdw table */
create or replace function do_nothing() returns trigger as $$
begin
	return new;
end
$$ language plpgsql;

create trigger on_update
	before update on ftable
	for each row execute procedure do_nothing();

/* will fail */
update parent set val = val + 1;
