X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7D89B528E0 for ; Tue, 7 Jun 2005 10:54:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62296-04 for ; Tue, 7 Jun 2005 13:54:47 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 89E4D528A9 for ; Tue, 7 Jun 2005 10:54:46 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id E0A0C356EF; Tue, 7 Jun 2005 06:54:48 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DF0B5356EC; Tue, 7 Jun 2005 06:54:48 -0700 (PDT) Date: Tue, 7 Jun 2005 06:54:48 -0700 (PDT) From: Stephan Szabo To: "M.D.G. Lange" Cc: pgsql-sql@postgresql.org Subject: Re: rule or trigger? In-Reply-To: <42A576E5.1040100@dltmedia.nl> Message-ID: <20050607065228.O97782@megazone.bigpanda.com> References: <42A576E5.1040100@dltmedia.nl> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/105 X-Sequence-Number: 21706 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.