@@ -186,17 +186,17 @@ NOTICE: should see this only if -100 fits in smallint
186
186
--
187
187
-- test foreign key error trapping
188
188
--
189
- create temp table master (f1 int primary key);
190
- create temp table slave (f1 int references master deferrable);
191
- insert into master values(1);
192
- insert into slave values(1);
193
- insert into slave values(2); -- fails
194
- ERROR: insert or update on table "slave " violates foreign key constraint "slave_f1_fkey "
195
- DETAIL: Key (f1)=(2) is not present in table "master ".
189
+ create temp table root (f1 int primary key);
190
+ create temp table leaf (f1 int references root deferrable);
191
+ insert into root values(1);
192
+ insert into leaf values(1);
193
+ insert into leaf values(2); -- fails
194
+ ERROR: insert or update on table "leaf " violates foreign key constraint "leaf_f1_fkey "
195
+ DETAIL: Key (f1)=(2) is not present in table "root ".
196
196
create function trap_foreign_key(int) returns int as $$
197
197
begin
198
198
begin -- start a subtransaction
199
- insert into slave values($1);
199
+ insert into leaf values($1);
200
200
exception
201
201
when foreign_key_violation then
202
202
raise notice 'caught foreign_key_violation';
@@ -238,8 +238,8 @@ begin;
238
238
239
239
savepoint x;
240
240
set constraints all immediate; -- fails
241
- ERROR: insert or update on table "slave " violates foreign key constraint "slave_f1_fkey "
242
- DETAIL: Key (f1)=(2) is not present in table "master ".
241
+ ERROR: insert or update on table "leaf " violates foreign key constraint "leaf_f1_fkey "
242
+ DETAIL: Key (f1)=(2) is not present in table "root ".
243
243
rollback to x;
244
244
select trap_foreign_key_2(); -- detects FK violation
245
245
NOTICE: caught foreign_key_violation
@@ -249,7 +249,7 @@ NOTICE: caught foreign_key_violation
249
249
(1 row)
250
250
251
251
commit; -- still fails
252
- ERROR: insert or update on table "slave " violates foreign key constraint "slave_f1_fkey "
253
- DETAIL: Key (f1)=(2) is not present in table "master ".
252
+ ERROR: insert or update on table "leaf " violates foreign key constraint "leaf_f1_fkey "
253
+ DETAIL: Key (f1)=(2) is not present in table "root ".
254
254
drop function trap_foreign_key(int);
255
255
drop function trap_foreign_key_2();
0 commit comments