I have created function calling external script with arguments:
CREATE OR REPLACE FUNCTION foo3(text, text) RETURNS TEXT AS $$
$ip = shift;
$username = shift;
$cmd="/bin/echo -n $ip $username > /tmp/test";
return `$cmd`;
$$ LANGUAGE plperlu;
It works fine when executed manually. But I wanted to call it every time new record in inserted in my table (a pass arguments which are record values):
postgres=# CREATE TRIGGER t_foo
postgres-# BEFORE UPDATE
postgres-# ON mapping
postgres-# FOR EACH ROW
postgres-# EXECUTE PROCEDURE foo3(OLD.ip, OLD.username);
ERROR: syntax error at or near "."
LINE 5: EXECUTE PROCEDURE foo3(OLD.ip, OLD.username);
^
Clearly I can not pass any arguments to that function. How to fix it?
As documented in the manual
Your function is neither declared as
returns triggernor does it have "no arguments".You need to create a trigger function that calls your function:
Then you create a trigger using that function: