(1 row)
drop function unreserved_test();
+-- Test TG_DEPTH
+create table tg_depth_a (id int not null primary key);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "tg_depth_a_pkey" for table "tg_depth_a"
+create table tg_depth_b (id int not null primary key);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "tg_depth_b_pkey" for table "tg_depth_b"
+create table tg_depth_c (id int not null primary key);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "tg_depth_c_pkey" for table "tg_depth_c"
+create function tg_depth_a_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ insert into tg_depth_b values (new.id);
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ return new;
+end;
+$$;
+create trigger tg_depth_a_tr before insert on tg_depth_a
+ for each row execute procedure tg_depth_a_tf();
+create function tg_depth_b_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ begin
+ execute 'insert into tg_depth_c values (' || new.id::text || ')';
+ exception
+ when sqlstate 'U9999' then
+ raise notice 'SQLSTATE = U9999: tg_depth = %', tg_depth;
+ end;
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ execute 'insert into tg_depth_c values (' || new.id::text || ')';
+ return new;
+end;
+$$;
+create trigger tg_depth_b_tr before insert on tg_depth_b
+ for each row execute procedure tg_depth_b_tf();
+create function tg_depth_c_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ raise exception sqlstate 'U9999';
+ return new;
+end;
+$$;
+create trigger tg_depth_c_tr before insert on tg_depth_c
+ for each row execute procedure tg_depth_c_tf();
+insert into tg_depth_a values (999);
+NOTICE: tg_depth_a_tr: tg_depth = 1
+NOTICE: tg_depth_b_tr: tg_depth = 2
+CONTEXT: SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+NOTICE: tg_depth_c_tr: tg_depth = 3
+CONTEXT: SQL statement "insert into tg_depth_c values (999)"
+PL/pgSQL function "tg_depth_b_tf" line 5 at EXECUTE statement
+SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+NOTICE: SQLSTATE = U9999: tg_depth = 2
+CONTEXT: SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+NOTICE: tg_depth_b_tr: tg_depth = 2
+CONTEXT: SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+NOTICE: tg_depth_c_tr: tg_depth = 3
+CONTEXT: SQL statement "insert into tg_depth_c values (999)"
+PL/pgSQL function "tg_depth_b_tf" line 11 at EXECUTE statement
+SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+ERROR: U9999
+CONTEXT: SQL statement "insert into tg_depth_c values (999)"
+PL/pgSQL function "tg_depth_b_tf" line 11 at EXECUTE statement
+SQL statement "insert into tg_depth_b values (new.id)"
+PL/pgSQL function "tg_depth_a_tf" line 4 at SQL statement
+drop table tg_depth_a, tg_depth_b, tg_depth_c;
+drop function tg_depth_a_tf();
+drop function tg_depth_b_tf();
+drop function tg_depth_c_tf();
select unreserved_test();
drop function unreserved_test();
+
+-- Test TG_DEPTH
+
+create table tg_depth_a (id int not null primary key);
+create table tg_depth_b (id int not null primary key);
+create table tg_depth_c (id int not null primary key);
+
+create function tg_depth_a_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ insert into tg_depth_b values (new.id);
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ return new;
+end;
+$$;
+create trigger tg_depth_a_tr before insert on tg_depth_a
+ for each row execute procedure tg_depth_a_tf();
+
+create function tg_depth_b_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ begin
+ execute 'insert into tg_depth_c values (' || new.id::text || ')';
+ exception
+ when sqlstate 'U9999' then
+ raise notice 'SQLSTATE = U9999: tg_depth = %', tg_depth;
+ end;
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ execute 'insert into tg_depth_c values (' || new.id::text || ')';
+ return new;
+end;
+$$;
+create trigger tg_depth_b_tr before insert on tg_depth_b
+ for each row execute procedure tg_depth_b_tf();
+
+create function tg_depth_c_tf() returns trigger
+ language plpgsql as $$
+begin
+ raise notice '%: tg_depth = %', tg_name, tg_depth;
+ raise exception sqlstate 'U9999';
+ return new;
+end;
+$$;
+create trigger tg_depth_c_tr before insert on tg_depth_c
+ for each row execute procedure tg_depth_c_tf();
+
+insert into tg_depth_a values (999);
+
+drop table tg_depth_a, tg_depth_b, tg_depth_c;
+drop function tg_depth_a_tf();
+drop function tg_depth_b_tf();
+drop function tg_depth_c_tf();