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 BA839528AA for ; Tue, 7 Jun 2005 07:28:58 -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 12692-02 for ; Tue, 7 Jun 2005 10:28:52 +0000 (GMT) Received: from s001.mxhosting.nl (unknown [213.206.92.11]) by svr1.postgresql.org (Postfix) with ESMTP id A817552881 for ; Tue, 7 Jun 2005 07:28:51 -0300 (ADT) Received: from pinbizz.xs4all.nl ([82.92.94.47] helo=[192.168.11.224]) by s001.mxhosting.nl with asmtp (Exim 4.40 (FreeBSD)) id 1DfamR-000E9a-Ed for pgsql-sql@postgresql.org; Tue, 07 Jun 2005 11:53:55 +0200 Message-ID: <42A576E5.1040100@dltmedia.nl> Date: Tue, 07 Jun 2005 12:28:53 +0200 From: "M.D.G. Lange" User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: rule or trigger? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - s001.mxhosting.nl X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [26 6] X-AntiAbuse: Sender Address Domain - dltmedia.nl X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/104 X-Sequence-Number: 21705 In order for a "dictionary" system I have created the following system: tbllanguages - ID - name Primary key ( ID ) tbldictionary - wordid - languageid - value Primary key ( wordid, languageid) The idea is to have a word id in several languages, so you only have to look up the word id and give the language you would like to get the message in and you'll be presented the translation. So far so good... only wordid is not unique, making it not suitable to use it in foreign keys... however I'd like a similar idea: tblsystemmessages - ID - wordid - pgsqlerrorcode Primary key ( ID ) "Foreign key" wordid references tbldictionary.wordid 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? Would the following rule do what I want? CREATE OR REPLACE RULE 'systemmessages_rule' AS ON INSERT TO "public.tblsystemmessages" DO INSTEAD ( IF count ( SELECT DISTINCT tbldictionary.wordid ) > 0 INSERT INTO tblsystemmessages ( ID, wordid, pgsqlerrorcode ) VALUES ( NEW.ID, NEW.wordid, NEW.pgsqlerrorcode ) ELSE NOTHING ); But would this not recursively call this rule? Michiel