For example, I have a table with 3 columns: a, b & c, in the function need set one of three columns, for example:
insert into test (a, b, c) values (...)
But need call the function from trigger, for example, when update a row set a column to true, when insert set b and when delete set c.
I try this:
CREATE OR REPLACE FUNCTION function_test(s_a, s_b, s_c)
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
BEGIN
INSERT INTO test(a, b, c)
VALUES(s_a, s_b, s_c);
RETURN NEW;
END;
$$
But postgres says: s_a does not exist.
My idea is create multiple trigger with this arguments, such as:
CREATE TRIGGER trigger_test
AFTER INSERT
ON test
FOR EACH ROW
EXECUTE PROCEDURE function_test(true, false, false);
CREATE TRIGGER trigger_test
AFTER UPDATE
ON test
FOR EACH ROW
EXECUTE PROCEDURE function_test(false, true, false);
My idea is create a audit table with current changes by username.