Trigger triggered from a foreign key - Mailing list pgsql-sql

From Victor Sterpu
Subject Trigger triggered from a foreign key
Date
Msg-id 50819898.9090508@caido.ro
Whole thread Raw
Responses Re: Trigger triggered from a foreign key
List pgsql-sql
I have this trigger that works fine. The trigger prevents the deletion 
of the last record.
But I want skip this trigger execution when the delete is done from a 
external key.
How can I do this?

This is the fk
ALTER TABLE focgdepartment  ADD CONSTRAINT fk_focgdep_idfocg FOREIGN KEY (idfocg)      REFERENCES focg (id) MATCH
SIMPLE     ON UPDATE NO ACTION ON DELETE CASCADE;
 

This is the trigger
CREATE FUNCTION check_focgdepartment_delete_restricted() RETURNS trigger 
AS $check_focgdepartment_delete_restricted$
BEGIN    IF ( (SELECT count(*) FROM focgdepartment WHERE idfocg = 
OLD.idfocg)=1)    THEN RAISE EXCEPTION 'Last record can not be deleted';    END IF;    RETURN OLD;
END;
$check_focgdepartment_delete_restricted$
LANGUAGE plpgsql;
CREATE TRIGGER focgdepartment_delete_restricted BEFORE DELETE ON 
focgdepartment FOR EACH ROW EXECUTE PROCEDURE 
check_focgdepartment_delete_restricted();


Thank you



pgsql-sql by date:

Previous
From: Liam Caffrey
Date:
Subject: Re: Recursive temporal query
Next
From: "David Johnston"
Date:
Subject: Re: Trigger triggered from a foreign key