Share RI trigger code between NO ACTION and RESTRICT cases.

These triggers are identical except for whether ri_Check_Pk_Match is to be
called, so factor out the common code to save a couple hundred lines.

Also, eliminate null-column checks in ri_Check_Pk_Match, since they're
duplicate with the calling functions and require unnecessary complication
in its API statement.

Simplify the way code is shared between RI_FKey_check_ins and
RI_FKey_check_upd, too.
pull/3/head
Tom Lane 14 years ago
parent 48756be9cf
commit fe3db74002
  1. 768
      src/backend/utils/adt/ri_triggers.c
  2. 26
      src/test/regress/expected/foreign_key.out
  3. 22
      src/test/regress/sql/foreign_key.sql

File diff suppressed because it is too large Load Diff

@ -1355,3 +1355,29 @@ select * from defc;
delete from defp where f1 = 1; -- fail
ERROR: update or delete on table "defp" violates foreign key constraint "defc_f1_fkey" on table "defc"
DETAIL: Key (f1)=(1) is still referenced from table "defc".
--
-- Test the difference between NO ACTION and RESTRICT
--
create temp table pp (f1 int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pp_pkey" for table "pp"
create temp table cc (f1 int references pp on update no action);
insert into pp values(12);
insert into pp values(11);
update pp set f1=f1+1;
insert into cc values(13);
update pp set f1=f1+1;
update pp set f1=f1+1; -- fail
ERROR: update or delete on table "pp" violates foreign key constraint "cc_f1_fkey" on table "cc"
DETAIL: Key (f1)=(13) is still referenced from table "cc".
drop table pp, cc;
create temp table pp (f1 int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pp_pkey" for table "pp"
create temp table cc (f1 int references pp on update restrict);
insert into pp values(12);
insert into pp values(11);
update pp set f1=f1+1;
insert into cc values(13);
update pp set f1=f1+1; -- fail
ERROR: update or delete on table "pp" violates foreign key constraint "cc_f1_fkey" on table "cc"
DETAIL: Key (f1)=(13) is still referenced from table "cc".
drop table pp, cc;

@ -960,3 +960,25 @@ alter table defc alter column f1 set default 1;
delete from defp where f1 = 0;
select * from defc;
delete from defp where f1 = 1; -- fail
--
-- Test the difference between NO ACTION and RESTRICT
--
create temp table pp (f1 int primary key);
create temp table cc (f1 int references pp on update no action);
insert into pp values(12);
insert into pp values(11);
update pp set f1=f1+1;
insert into cc values(13);
update pp set f1=f1+1;
update pp set f1=f1+1; -- fail
drop table pp, cc;
create temp table pp (f1 int primary key);
create temp table cc (f1 int references pp on update restrict);
insert into pp values(12);
insert into pp values(11);
update pp set f1=f1+1;
insert into cc values(13);
update pp set f1=f1+1; -- fail
drop table pp, cc;

Loading…
Cancel
Save