Trigger violates foreign key constraint - Mailing list pgsql-hackers

From Laurenz Albe
Subject Trigger violates foreign key constraint
Date
Msg-id b81fe38fcc25a81be6e2e5b3fc1ff624130762fa.camel@cybertec.at
Whole thread Raw
Responses Re: Trigger violates foreign key constraint
Re: Trigger violates foreign key constraint
List pgsql-hackers
CREATE TABLE parent (id integer PRIMARY KEY);

CREATE TABLE child (id integer REFERENCES parent ON DELETE CASCADE);

CREATE FUNCTION silly() RETURNS trigger LANGUAGE plpgsql AS 'BEGIN RETURN NULL; END;';

CREATE TRIGGER silly BEFORE DELETE ON child FOR EACH ROW EXECUTE FUNCTION silly();

INSERT INTO parent VALUES (1);

INSERT INTO child VALUES (1);

DELETE FROM parent WHERE id = 1;

TABLE child;
 id
════
  1
(1 row)

The trigger function cancels the cascaded delete on "child", and we are left with
a row in "child" that references no row in "parent".

Yours,
Laurenz Albe



pgsql-hackers by date:

Previous
From: "Drouvot, Bertrand"
Date:
Subject: Re: Synchronizing slots from primary to standby
Next
From: Peter Eisentraut
Date:
Subject: Clean up some pg_dump tests