X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4C088D9C0F for ; Fri, 21 Oct 2005 11:13:47 -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 84138-06 for ; Fri, 21 Oct 2005 14:13:43 +0000 (GMT) Received: from halfgaar.kicks-ass.net (cc503261-a.eelde1.dr.home.nl [217.121.237.58]) by svr1.postgresql.org (Postfix) with ESMTP id 2B1D8D7207 for ; Fri, 21 Oct 2005 11:13:45 -0300 (ADT) Received: from localhost ([127.0.0.1]) by halfgaar.kicks-ass.net with esmtp (Exim 4.50) id 1ESxeW-0004hg-N9 for pgsql-sql@postgresql.org; Fri, 21 Oct 2005 16:13:48 +0200 Message-ID: <4358F79B.1000409@gmail.com> Date: Fri, 21 Oct 2005 16:13:47 +0200 From: Wiebe Cazemier User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050729) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Delete rule chain stops unexpectedly Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.842 required=5 tests=[FORGED_RCVD_HELO=0.05, RCVD_IN_NJABL_DUL=1.655, RCVD_IN_SORBS_DUL=0.137] X-Spam-Level: * X-Archive-Number: 200510/242 X-Sequence-Number: 23095 Hi, I've got the following table (contents not really relevant): CREATE TABLE _rating_params ( id SERIAL PRIMARY KEY, letter CHAR(1) NOT NULL CHECK (letter = 'E' OR letter = 'F'), superparam_id INTEGER REFERENCES _rating_params, seq_num INTEGER NOT NULL DEFAULT 1, name_id INTEGER NOT NULL REFERENCES messages_eng, max_score NUMERIC(4) ); which I manipulate with the view "rating_params". The delete rules on this view act very strangely. They are, with comments I'll explain: -- Actually delete the rating param, along with all it's subparams CREATE RULE delete1 AS ON DELETE TO rating_params DO INSTEAD ( INSERT INTO debuglog (line) VALUES('step1'); -- When I comment out this line, then the other rules _are_ executed. If I leave it here, execution stops here, after this query. DELETE FROM _rating_params WHERE id = OLD.id OR superparam_id=OLD.id; INSERT INTO debuglog (line) VALUES('step2'); ); -- Renumber sequences in order not to get any gaps CREATE RULE delete2 AS ON DELETE TO rating_params DO ALSO ( UPDATE _rating_params SET seq_num = seq_num - 1 WHERE superparam_id = OLD.superparam_id AND seq_num > OLD.seq_num; INSERT INTO debuglog (line) VALUES('step3'); ); -- Remove the max. score from any maximum total scores CREATE RULE delete3 AS ON DELETE TO rating_params WHERE OLD.superparam_id IS NOT NULL DO ALSO ( UPDATE _rating_params SET max_score = rating_param_max_score(id) WHERE id = OLD.superparam_id; INSERT INTO debuglog (line) VALUES('step4'); ); As you can see I've put several debug messages in the rules. As it is now, only step1 is put in the debuglog table. When I remove the query to delete from the _rating_params table, all other rules are executed and the debug messages are inserted. The strangest is yet to come. Normally I would delete with "delete from rating_params where id=5". But, when I do "explain analyze delete from rating_params where id=5", all the rules _are_ executed properly. I'm using postgresql 8.0.3. Anybody got an idea? Thanks in advance.