Commit 3f0f9912 authored by Peter Eisentraut's avatar Peter Eisentraut

Remove master/slave usage from plpgsql tests

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/E393EC88-377F-4C59-A67A-69F2A38D17C7@yesql.se
parent db1f2891
......@@ -186,17 +186,17 @@ NOTICE: should see this only if -100 fits in smallint
--
-- test foreign key error trapping
--
create temp table master(f1 int primary key);
create temp table slave(f1 int references master deferrable);
insert into master values(1);
insert into slave values(1);
insert into slave values(2); -- fails
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "master".
create temp table root(f1 int primary key);
create temp table leaf(f1 int references root deferrable);
insert into root values(1);
insert into leaf values(1);
insert into leaf values(2); -- fails
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "root".
create function trap_foreign_key(int) returns int as $$
begin
begin -- start a subtransaction
insert into slave values($1);
insert into leaf values($1);
exception
when foreign_key_violation then
raise notice 'caught foreign_key_violation';
......@@ -238,8 +238,8 @@ begin;
savepoint x;
set constraints all immediate; -- fails
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "master".
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "root".
rollback to x;
select trap_foreign_key_2(); -- detects FK violation
NOTICE: caught foreign_key_violation
......@@ -249,7 +249,7 @@ NOTICE: caught foreign_key_violation
(1 row)
commit; -- still fails
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "master".
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
DETAIL: Key (f1)=(2) is not present in table "root".
drop function trap_foreign_key(int);
drop function trap_foreign_key_2();
......@@ -127,18 +127,18 @@ select test_variable_storage();
-- test foreign key error trapping
--
create temp table master(f1 int primary key);
create temp table root(f1 int primary key);
create temp table slave(f1 int references master deferrable);
create temp table leaf(f1 int references root deferrable);
insert into master values(1);
insert into slave values(1);
insert into slave values(2); -- fails
insert into root values(1);
insert into leaf values(1);
insert into leaf values(2); -- fails
create function trap_foreign_key(int) returns int as $$
begin
begin -- start a subtransaction
insert into slave values($1);
insert into leaf values($1);
exception
when foreign_key_violation then
raise notice 'caught foreign_key_violation';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment