Thread: rule calls function, passing OLD
Hello. I am a beginner with pgsql and struggeling with the documentation. Why can't I pass OLD from my rule to the function so the function knows on which row the rule was called? test=# \i '/home/myAccount/Documents/Datenbank Layout/Postgres Sytax/test/Regeln2' CREATE FUNCTION psql:/home/myAccount/Documents/Datenbank Layout/Postgres Sytax/test/Regeln2:16: ERROR: function deny_namen_telefonverweise(namen_telefonverweise) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. test=# When I pass an integer instead, everything works. Is there another way of letting the function know on which row the rule was called? CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(record) RETURNS void AS ' DECLARE result RECORD; BEGIN /* DELETE ROW LATER */ SELECT 1+1; END; ' LANGUAGE 'plpgsql'; CREATE OR REPLACE RULE deny_namen_Telefonverweise AS ON DELETE TO Namen_Telefonverweise DO INSTEAD SELECT DENY_Namen_Telefonverweise(OLD);
On Wed, 14 Jul 2004, R.Welz wrote: > test=# \i '/home/myAccount/Documents/Datenbank Layout/Postgres > Sytax/test/Regeln2' > CREATE FUNCTION > psql:/home/myAccount/Documents/Datenbank Layout/Postgres > Sytax/test/Regeln2:16: ERROR: function > deny_namen_telefonverweise(namen_telefonverweise) does not exist > HINT: No function matches the given name and argument types. You may > need to add explicit type casts. I'd think you'd want the function declared as above (using the specific rowtype), not as one taking record, which appears to work for me. > CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(record) RETURNS > void AS ' > DECLARE > result RECORD; > > BEGIN > /* DELETE ROW LATER */ > SELECT 1+1; > > END; > ' > LANGUAGE 'plpgsql'; > > > CREATE OR REPLACE RULE deny_namen_Telefonverweise AS ON DELETE TO > Namen_Telefonverweise > DO INSTEAD > SELECT DENY_Namen_Telefonverweise(OLD);
"R.Welz" <linuxprodukte@gmx.de> writes: > CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(record) RETURNS > void AS ' > ... > LANGUAGE 'plpgsql'; You can't do that. CVS tip tells you so immediately: ERROR: plpgsql functions cannot take type record but I think 7.4 wouldn't notice until you try to execute the function. You could declare the function as taking the specific rowtype of the table, though: CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(Namen_Telefonverweise) RETURNS Notice that the error message you're getting is specifically complaining about the lack of such a function. regards, tom lane