mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
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
This commit is contained in:
parent
db1f28917b
commit
3f0f99125e
@ -186,17 +186,17 @@ NOTICE: should see this only if -100 fits in smallint
|
|||||||
--
|
--
|
||||||
-- test foreign key error trapping
|
-- 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 root values(1);
|
||||||
insert into slave values(1);
|
insert into leaf values(1);
|
||||||
insert into slave values(2); -- fails
|
insert into leaf values(2); -- fails
|
||||||
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
|
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
|
||||||
DETAIL: Key (f1)=(2) is not present in table "master".
|
DETAIL: Key (f1)=(2) is not present in table "root".
|
||||||
create function trap_foreign_key(int) returns int as $$
|
create function trap_foreign_key(int) returns int as $$
|
||||||
begin
|
begin
|
||||||
begin -- start a subtransaction
|
begin -- start a subtransaction
|
||||||
insert into slave values($1);
|
insert into leaf values($1);
|
||||||
exception
|
exception
|
||||||
when foreign_key_violation then
|
when foreign_key_violation then
|
||||||
raise notice 'caught foreign_key_violation';
|
raise notice 'caught foreign_key_violation';
|
||||||
@ -238,8 +238,8 @@ begin;
|
|||||||
|
|
||||||
savepoint x;
|
savepoint x;
|
||||||
set constraints all immediate; -- fails
|
set constraints all immediate; -- fails
|
||||||
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
|
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
|
||||||
DETAIL: Key (f1)=(2) is not present in table "master".
|
DETAIL: Key (f1)=(2) is not present in table "root".
|
||||||
rollback to x;
|
rollback to x;
|
||||||
select trap_foreign_key_2(); -- detects FK violation
|
select trap_foreign_key_2(); -- detects FK violation
|
||||||
NOTICE: caught foreign_key_violation
|
NOTICE: caught foreign_key_violation
|
||||||
@ -249,7 +249,7 @@ NOTICE: caught foreign_key_violation
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
commit; -- still fails
|
commit; -- still fails
|
||||||
ERROR: insert or update on table "slave" violates foreign key constraint "slave_f1_fkey"
|
ERROR: insert or update on table "leaf" violates foreign key constraint "leaf_f1_fkey"
|
||||||
DETAIL: Key (f1)=(2) is not present in table "master".
|
DETAIL: Key (f1)=(2) is not present in table "root".
|
||||||
drop function trap_foreign_key(int);
|
drop function trap_foreign_key(int);
|
||||||
drop function trap_foreign_key_2();
|
drop function trap_foreign_key_2();
|
||||||
|
@ -127,18 +127,18 @@ select test_variable_storage();
|
|||||||
-- test foreign key error trapping
|
-- 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 root values(1);
|
||||||
insert into slave values(1);
|
insert into leaf values(1);
|
||||||
insert into slave values(2); -- fails
|
insert into leaf values(2); -- fails
|
||||||
|
|
||||||
create function trap_foreign_key(int) returns int as $$
|
create function trap_foreign_key(int) returns int as $$
|
||||||
begin
|
begin
|
||||||
begin -- start a subtransaction
|
begin -- start a subtransaction
|
||||||
insert into slave values($1);
|
insert into leaf values($1);
|
||||||
exception
|
exception
|
||||||
when foreign_key_violation then
|
when foreign_key_violation then
|
||||||
raise notice 'caught foreign_key_violation';
|
raise notice 'caught foreign_key_violation';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user