Postgresql trigger function with parameters

You do not need to pass the NEW and OLD as parameters to the trigger function. They are automagically available there:

http://www.postgresql.org/docs/9.1/interactive/trigger-definition.html :

The trigger function must be declared as a function taking no arguments and returning type trigger. (The trigger function receives its input through a specially-passed TriggerData structure, not in the form of ordinary function arguments.)

About the records passed to the trigger procedure, please see http://www.postgresql.org/docs/9.1/interactive/plpgsql-trigger.html :

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

As SeldomNeedy pointed in the comment below, you can still pass and use parameters to the trigger function. You declare the function as taking no parameters, but when defining the trigger (by CREATE TRIGGER), you may add some.

They will be available for the trigger as TG_NARG (the number of such parameters), and TG_ARGV[] (an array of text values).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)