Re: rule or trigger?

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "M(dot)D(dot)G(dot) Lange" <mlange(at)dltmedia(dot)nl>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: rule or trigger?
Date: 2005-06-07 13:54:48
Message-ID: 20050607065228.O97782@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-06-07 14:36:53 Re: to listadmin
Previous Message M.D.G. Lange 2005-06-07 10:28:53 rule or trigger?