Re: help on delete trigger. - Mailing list pgsql-general

From Gregory Wood
Subject Re: help on delete trigger.
Date
Msg-id 012201c124d3$5aae0d20$7889ffcc@comstock.com
Whole thread Raw
In response to help on delete trigger.  ("Sundararajan" <sdn@srasys.co.in>)
List pgsql-general
This code looks fine to me, other than missing the actual trigger statement
is missing. Assuming table 1 is named apps:

DROP TRIGGER OnApplicationsDelete ON apps;
DROP FUNCTION ApplicationsDeleteFn();
CREATE FUNCTION ApplicationsDeleteFn()
RETURNS OPAQUE
AS '
 BEGIN
delete from ports where appName=OLD.appName;
 RETURN OLD;

 END;
'
LANGUAGE 'plpgsql';
CREATE TRIGGER OnApplicationsDelete BEFORE DELETE ON apps FOR EACH ROW
EXECUTE PROCEDURE ApplicationsDeleteFn();

But the question is, would it be better to use a foreign key? If you put a
foreign key on ports.appName that REFERENCES apps.appName, you could define
it as an ON DELETE CASCADE relationship. Meaning that deleting the value
from the apps table would cascade that delete to the ports table.

Hope this helps,

Greg




pgsql-general by date:

Previous
From: Jochem van Dieten
Date:
Subject: PostgresQL equivalent of NOCOUNT
Next
From: Craig Longman
Date:
Subject: cmd-line interface