Rules - Mailing list pgsql-hackers

From Darko Prenosil
Subject Rules
Date
Msg-id 200406091350.25519.darko.prenosil@finteh.hr
Whole thread Raw
Responses Re: Rules
List pgsql-hackers
Why is this wrong ?:

DROP SCHEMA test CASCADE ;
CREATE SCHEMA test;

CREATE TABLE test.parent (id serial PRIMARY KEY,opis text 
);

CREATE TABLE test.child_data (id serial PRIMARY KEY,id_parent int ,podaci text,FOREIGN KEY (id_parent) REFERENCES
test.parent(id)
);

CREATE VIEW test.child AS SELECT     p.id AS id,        p.opis AS opis,        c.id AS id_data,        c.id_parent AS
id_parent,       c.podaci AS podaci FROMtest.parent p, test.child_data c WHERE c.id_parent = p.id;
 
CREATE FUNCTION test.testfi(test.child) RETURNS bool AS '
DECLARE_NEW ALIAS FOR \$1;
BEGINRAISE NOTICE ''%'',_NEW.opis;INSERT INTO test.parent (id,opis) VALUES (_NEW.id,_NEW.opis);INSERT INTO
test.child_data(id,id_parent,podaci) VALUES 
 
(_NEW.id_data,_NEW.id,_NEW.podaci);RETURN TRUE;
END; ' 
LANGUAGE 'plpgsql';

CREATE RULE child_ins AS ON INSERT TO test.child
DO INSTEAD SELECT test.testfi(NEW);


INSERT INTO test.child(id,id_data,opis,podaci) VALUES (1,1,'Opis','podaci');


Gives:(-403)ERROR:  cannot handle whole-row reference

Can I pass NEW & OLD from rule into function in any way ?
Any suggestions ?

Regards !


pgsql-hackers by date:

Previous
From: "Thomas Hallgren"
Date:
Subject: Re: Question regarding dynamic_library_path
Next
From: Andrew Dunstan
Date:
Subject: Re: Question regarding dynamic_library_path