
CREATE TABLE test_table (a int4, b text);
COPY test_table FROM stdin;
1	aaa
2	bbb
3	ccc
4	ddd
\.

CREATE VIEW test_view AS SELECT a,b FROM test_table WHERE (a % 2) = 1;


CREATE OR REPLACE FUNCTION test_upd_fn(test_view, test_view) RETURNS boolean AS $$
BEGIN
	RAISE NOTICE 'test_upd_fn(a1=%, b1=%, a2=%, b2=%)', $1.a,$1.b, $2.a,$2.b;
	UPDATE test_table SET b=b || 'x' WHERE a=$1.a;
	RETURN true;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE RULE my_upd_rule AS ON UPDATE TO test_view
DO INSTEAD
SELECT test_upd_fn(v1.*, v2.*) FROM test_view v1, test_view v2 WHERE v1.a=NEW.a AND v2.a=OLD.a;


SELECT * FROM test_table;
SELECT * FROM test_view;

UPDATE test_view SET b='ccc2' WHERE a=3;

SELECT * FROM test_view;

