Re: help on delete trigger.

From: "Gregory Wood" <gregw(at)com-stock(dot)com>
To: "Sundararajan" <sdn(at)srasys(dot)co(dot)in>
Cc: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: help on delete trigger.
Date: 2001-08-14 15:11:05
Message-ID: 012201c124d3$5aae0d20$7889ffcc@comstock.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-08-14 15:16:57 Re: PostgresQL equivalent of NOCOUNT
Previous Message Vince Vielhaber 2001-08-14 15:05:43 Re: Is the bug system active?

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2001-08-14 15:30:00 Re: [SQL] Re: Arithmetic operation on DATE
Previous Message Jan Wieck 2001-08-14 15:01:19 Re: help on delete trigger.