1

I want to create a trigger, somehow like this:

CREATE TRIGGER foo 
AFTER UPDATE OR INSERT ON bar 
FOR EACH ROW EXECUTE PROCEDURE baz(NEW.id);

The part with NEW.id doesn't work. How can I send values from the changed row (id for instance) to the trigger-function.

1 Answer 1

2

The trigger function (procedure) knows NEW and OLD automatically. No need to pass those as parameters. Read more in the chapter on Trigger Procedures in the manual:

When a PL/pgSQL function is called as a trigger, several special variables are created automatically in the top-level block. They are:

NEW

Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is NULL in statement-level triggers and for DELETE operations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.