Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id C601C475DD9 for ; Wed, 22 May 2002 08:32:56 -0400 (EDT) Received: from Donald.bks (unknown [203.145.133.13]) by postgresql.org (Postfix) with ESMTP id 0EA4C4762E8 for ; Wed, 22 May 2002 08:31:48 -0400 (EDT) Received: from Larry.bks (root@Larry.bks [200.2.1.10]) by Donald.bks (8.11.6/8.11.2) with ESMTP id g4MCZYv06771 for ; Wed, 22 May 2002 18:05:37 +0530 Received: from localhost (bhuvan@localhost) by Larry.bks (8.9.3/8.8.5) with ESMTP id RAA31446 for ; Wed, 22 May 2002 17:54:53 +0530 X-Authentication-Warning: Larry.bks: bhuvan owned process doing -bs Date: Wed, 22 May 2002 17:54:53 +0530 (IST) From: Bhuvan A X-Sender: bhuvan@Larry To: pgsql-sql@postgresql.org Subject: Compatibility Issue of CREATE RULE in 7.2 Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200205/229 X-Sequence-Number: 7864 hi, Recently, i have migrated from 7.1.2 to 7.2. Here found a problem in 7.2 while using RULEs. In 7.1.2, action of the rules gets executed BEFORE for all the events. But in 7.2, action gets executed BEFORE for INSERT alone and AFTER for all other events. In 7.1.2, bhuvan=# CREATE TABLE rule_test (key text, value text); CREATE bhuvan=# CREATE RULE rule_test_rule AS ON insert TO rule_test do delete from rule_test where key = new.key; CREATE bhuvan=# INSERT INTO rule_test values ('key', 'oldvalue'); INSERT 22317402 1 bhuvan=# SELECT * from rule_test ; key | value -----+---------- key | oldvalue (1 row) bhuvan=# INSERT INTO rule_test values ('key', 'newvalue'); INSERT 22317403 1 bhuvan=# SELECT * from rule_test ; key | value -----+---------- key | newvalue (1 row) bhuvan=# // since the rule has been executed BEFORE INSERT But in 7.2, // the same results in deleting 2 records :) // since the rule gets executed AFTER INSERT. So would like to know an alternate way to fix this problem. Since i wont like checking for existence of the key and do insert or update accordingly, everytime from my code. Hope there would be some lights on to solve this problem. regards, bhuvaneswaran.