CREATE TABLE test (id int NOT NULL, val integer);

create or replace procedure rebuild_test(
) as
$body$
declare
    l_code  text:= E'create or replace function public.test_selector(
) returns setof public.test as
\$body\$
	select * from  error_name
\$body\$ language sql;';
begin
    execute l_code;
    perform public.test_selector();
end
$body$ language plpgsql;


create or replace function test_trg(
) returns trigger as
$body$
declare
begin
    call public.rebuild_test();
    return NULL;
end
$body$ language plpgsql;

create trigger test_trigger after insert or update or delete on test for each row execute function test_trg();

alter table test enable replica trigger test_trigger;

CREATE SUBSCRIPTION test_sub CONNECTION 'port=XXXX user=postgres dbname=postgres' PUBLICATION test_pub;
