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)



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to