Received: from rasmus.uib.no (exim@rasmus.uib.no [129.177.12.30]) by hub.org (8.10.1/8.10.1) with ESMTP id e6S9YmB67029 for ; Fri, 28 Jul 2000 05:34:49 -0400 (EDT) Received: from (wkst6) [194.248.181.116] by rasmus.uib.no with smtp (Exim 3.14) id 13I6XW-0006It-00; Fri, 28 Jul 2000 11:34:46 +0200 Message-ID: <00f001bff876$cc57f8d0$74b5f8c2@wkst6> From: "=?iso-8859-1?B?QW5kcukgTuZzcw==?=" To: References: <200007272216.AAA28690@hot.jw.home> Subject: Re: Conditional rule? Date: Fri, 28 Jul 2000 11:32:46 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Archive-Number: 200007/269 ----- Original Message ----- > No. The rule > > CREATE RULE newsrule AS ON INSERT TO news > WHERE new.publishtime NOTNULL DO > INSERT INTO news_unpublished VALUES (new.id); > > should do the job perfectly. Maybe you want to have the > following rules too: The following happens: rules=# insert into news (title, time) values('Hei', now()); ERROR: referential integrity violation - key referenced from news_unpublished not found in news Seems the data is inserted into news_unpublished first, thereby violating the constraint I have defined for the news_id field (see below). After removing the constraint a second problem arose; the id created for news (serial) was 4, while the id inserted into news_unpublished was 3. So far a trigger procedure seems to be the best solution. > CREATE RULE newsrule4 AS ON DELETE TO news > WHERE old.publishtime NOTNULL DO > DELETE FROM news_unpublished WHERE news_unpublished.id = old.id; This is also achieved by the following right? (id is the primary key for news): create table news_unpublished ( news_id int references news on delete cascade ); André Nęss