Reputation: 1
The PostgreSQL manual describes OLD, NEW, TG_OP etc. as "special variables" made available to PL/pgSQL trigger procedures. It also defines an IMMUTABLE function as "guaranteed to return the same results given the same arguments forever".
Can these special variables be seen as trigger procedure arguments in the context of evaluating the function's purity? Or are they more akin to variables external to the function, so that any trigger procedure dependent on them should never be marked IMMUTABLE?
Upvotes: 0
Views: 271
Reputation: 4423
The OLD, NEW, TG_OP are more like a global variables that are available inside the triggered function. You don't explicitly define them as arguments:
CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER AS...
...
IF TG_OP = 'INSERT' AND NEW.field_foo =....
The function foo has no arguments defined, however TG_OP and NEW are available.
Upvotes: 0