Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id B86E34761B0 for ; Wed, 22 May 2002 08:25:11 -0400 (EDT) Received: from Donald.bks (unknown [203.145.133.13]) by postgresql.org (Postfix) with ESMTP id A1D01475E06 for ; Wed, 22 May 2002 08:23:54 -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 g4MCRev06720 for ; Wed, 22 May 2002 17:57:43 +0530 Received: from localhost (bhuvan@localhost) by Larry.bks (8.9.3/8.8.5) with ESMTP id RAA31256 for ; Wed, 22 May 2002 17:46:59 +0530 X-Authentication-Warning: Larry.bks: bhuvan owned process doing -bs Date: Wed, 22 May 2002 17:46:59 +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/235 X-Sequence-Number: 7870 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 get executed BEFORE for all the events. But in 7.2, action get 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.