Add regression tests for TG_DEPTH in PL/pgSQL. depth
authorKevin Grittner <Kevin.Grittner@wicourts.gov>
Fri, 28 Jan 2011 22:57:44 +0000 (16:57 -0600)
committerKevin Grittner <Kevin.Grittner@wicourts.gov>
Fri, 28 Jan 2011 22:57:44 +0000 (16:57 -0600)
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql

index 22ccce212c480f3a6406625825dc520c310f1e84..1fd6c43f0e953d11699dc382c1be7e8ba09afce2 100644 (file)
@@ -4240,3 +4240,78 @@ select unreserved_test();
 (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();
index d0f4e3b5e1f5c0f10f8f9cd48569cfd508b6b987..61cf47cb68e06a911e6e2f5d0dd5d0fe7da195fe 100644 (file)
@@ -3375,3 +3375,57 @@ $$ language plpgsql;
 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();