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 E4C66329D7F for ; Mon, 13 Sep 2004 19:13:28 +0100 (BST) 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 86664-01 for ; Mon, 13 Sep 2004 18:13:23 +0000 (GMT) Received: from pillette.com (adsl-67-119-5-202.dsl.snfc21.pacbell.net [67.119.5.202]) by svr1.postgresql.org (Postfix) with ESMTP id 0B3AD329D7A for ; Mon, 13 Sep 2004 19:13:22 +0100 (BST) Received: (from andrew@localhost) by pillette.com (8.11.6/8.11.6) id i8DID8Y10812; Mon, 13 Sep 2004 11:13:08 -0700 Date: Mon, 13 Sep 2004 11:13:08 -0700 From: andrew@pillette.com Message-Id: <200409131813.i8DID8Y10812@pillette.com> Subject: Re: CREATE RULE ignored, what did I do wrong To: Tom Lane Cc: andrew@pillette.com, pgsql-sql@postgresql.org X-Originating-IP: 192.168.1.208 X-Mailer: Webmin 0.940 MIME-Version: 1.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME X-Spam-Level: Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Archive-Number: 200409/99 X-Sequence-Number: 18945 I was trying to implement a pseudo-delete, where the (millions of) records in several child tables were actually deleted, but a flag was set in the summary table instead of deleting it, as an archiving mechanism. (If the flag was already set, the WHERE clause in the RULE should be false, and the delete happen as usual?!) The FK relation below has the summary table as the child, and isn't critical. It's the tables for which this is the parent that are the issue. Do you have an idea how to implement this best? Tom Lane wrote .. > andrew@pillette.com writes: > > Foreign-key constraints: > > "$1" FOREIGN KEY (smoothing_id) REFERENCES smoothing_algorithm(smoothing_id) > ON UPDATE CASCADE ON DELETE CASCADE > > Rules: > > del_smoothed_rank_episode AS ON DELETE TO smoothed_rank_episode > > WHERE (NOT old.is_deleted) DO INSTEAD ... > > The DELETE commands generated by the foreign key ON DELETE CASCADE will > get rewritten by your ON DELETE rule. You probably do not want to do > this; or at least not make it an INSTEAD rule. > > There has been some debate in the past about whether rules should be > able to break foreign-key constraints, but I tend to class it as a > "you should know what you're doing" feature. Preventing this kind > of error would inevitably result in a serious reduction of the power > of the rule feature. > > regards, tom lane