summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Grittner2011-01-28 22:57:44 +0000
committerKevin Grittner2011-01-28 22:57:44 +0000
commit4f10ac146847c1d660ebe50f7fa3ad2c4f61f9ee (patch)
treec0f502d19f68c7f10a1dd03f35b753fa6adb988d
parentabf34a11756bd0f3ab738d3554051abd7edb1557 (diff)
Add regression tests for TG_DEPTH in PL/pgSQL.depth
-rw-r--r--src/test/regress/expected/plpgsql.out75
-rw-r--r--src/test/regress/sql/plpgsql.sql54
2 files changed, 129 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index 22ccce212c..1fd6c43f0e 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -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();
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index d0f4e3b5e1..61cf47cb68 100644
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -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();