Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id D13EB47597C for ; Thu, 23 May 2002 02:04:21 -0400 (EDT) Received: from Donald.bks (unknown [203.145.133.13]) by postgresql.org (Postfix) with ESMTP id 452FA475957 for ; Thu, 23 May 2002 02:04:13 -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 g4N67kv11446 for ; Thu, 23 May 2002 11:37:46 +0530 Received: from localhost (bhuvan@localhost) by Larry.bks (8.9.3/8.8.5) with ESMTP id LAA18893 for ; Thu, 23 May 2002 11:27:04 +0530 X-Authentication-Warning: Larry.bks: bhuvan owned process doing -bs Date: Thu, 23 May 2002 11:27:04 +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/249 X-Sequence-Number: 7884 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.