![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
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. 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[]); |
#2
| |||
| |||
|
|
Right, except: create table test (a text, b int); create or replace rule test_rule as on insert to test where exists(select 1 from test where a = NEW.a) do instead select * from test; insert into test (a,b) VALUES ('first',2); a | b -------+--- first | 2 (1 row) select * from test; a | b -------+--- first | 2 (1 row) Now, the select on the first insert should NOT have happened..... Since this is a do instead rule. The insert should of course happen, since it's not present in the table. Or am I missing the point completely? |
![]() |
| Thread Tools | |
| Display Modes | |
| |