RULES doesn't work as expected - Mailing list pgsql-bugs

From John Hansen
Subject RULES doesn't work as expected
Date
Msg-id 5066E5A966339E42AA04BA10BA706AE5622B@rodrick.geeknet.com.au
Whole thread Raw
Responses Re: RULES doesn't work as expected  (Richard Huxton <dev@archonet.com>)
List pgsql-bugs
It seems rules don't work as expected.
I could be wrong,... In which case, what am I doing wrong?

Clearly, the first insert below should not update the table as well.

... John


CREATE TABLE test (a text, b int4[]);

CREATE RULE test_rule AS 
  ON INSERT TO test 
  WHERE exists(SELECT 1 FROM test WHERE a = NEW.a)
  DO INSTEAD
    UPDATE test SET b = b + NEW.b WHERE a = NEW.a;


db1=# INSERT INTO test (a,b) VALUES (1,'{1}'::int4[]);
INSERT 0 1
db1=# SELECT * FROM test;
 a |   b
---+-------
 1 | {1,1}
(1 row)

db1=# INSERT INTO test (a,b) VALUES (1,'{1}'::int4[]);
INSERT 0 0
db1=# SELECT * FROM test;
 a |    b
---+---------
 1 | {1,1,1}
(1 row)



pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: Returned due to virus; was:Hello
Next
From: "Gustav Lindenberg"
Date:
Subject: BUG #1389: 2 x 3.1 Gz Intel Cpu, 4Gb RAM, 2Gb Swap, Linux, Kernel 2.4.21-20.ELsmp #1 SMP