Earlier today Hakan Kocaman ([EMAIL PROTECTED]) posted a query on general "Issue with functions in Rule".

Turned out the problem is with a function that takes a compound type based on a view with ORDER BY. If you add/remove ORDER BY to the view definition in the attached it doesn't recognise the type (I think)

The error is different in 8.0.x and 8.1.x but occurs in both.

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

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


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;

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to