Re: rule or trigger? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: rule or trigger?
Date
Msg-id 20050607065228.O97782@megazone.bigpanda.com
Whole thread Raw
In response to rule or trigger?  ("M.D.G. Lange" <mlange@dltmedia.nl>)
List pgsql-sql
On Tue, 7 Jun 2005, M.D.G. Lange wrote:

> It is not possible to create a constraint Foreign key for "wordid". No
> problem there, but I want to be certain that a given wordid exists in
> tbldictionary.
> Would I have to create a "RULE" or a "TRIGGER" to be certain that the
> wordid is existing in tbldictionary in whatever language.
>
> I have the idea that a trigger will not prevent the insertion, or did I
> not read well enough?

What you can do in an after trigger is test that the value exists in the
other table or raise an error (which is basically what the foreign key
triggers do).

There are some issues with writing your own, the first being that to get
full foreign key style semantics you need triggers on the referenced table
as well, however if removing or updating the wordid in tbldictionary is
uncommon, you can probably avoid it.


pgsql-sql by date:

Previous
From: "M.D.G. Lange"
Date:
Subject: rule or trigger?
Next
From: Tom Lane
Date:
Subject: Re: to listadmin