Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id B0183476DDA for ; Thu, 13 Jun 2002 10:47:59 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 303CA476D9F for ; Thu, 13 Jun 2002 10:36:00 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g5DEa1b19320; Thu, 13 Jun 2002 10:36:01 -0400 (EDT) To: Svenn Helge Grindhaug Cc: pgsql-sql@postgresql.org Subject: Re: Rule problem In-reply-to: References: Comments: In-reply-to Svenn Helge Grindhaug message dated "Thu, 13 Jun 2002 12:11:37 +0200" Date: Thu, 13 Jun 2002 10:36:00 -0400 Message-ID: <19317.1023978960@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200206/172 X-Sequence-Number: 8137 Svenn Helge Grindhaug writes: > create rule a_delete as > on delete to a do > delete from b where id1 = old.id1; > create rule c_delete as > on delete to c do > delete from a where id1 = (select id1 from b where id2 = old.id2); The a_delete rule is run before the actual "DELETE FROM a" command, so by the time the latter runs, the b row is gone, and no match exists. I'd be inclined to think about doing this with foreign keys (set up for ON DELETE CASCADE) instead of handmade rules. If you really want to do it by hand, triggers will probably work better than rules. regards, tom lane