Can a nested function determine it is being called within a trigger?

Started by Basil Bourquealmost 15 years ago3 messagesgeneral
Jump to latest
#1Basil Bourque
basil.list@me.com

When a trigger calls a function, that function can determine if it is being called from within a trigger by testing for a value in the special variable "TG_OP".

But what if a trigger calls a function that calls a 2nd function via the "PERFORM" command? Can that 2nd function tell if it is being run in a trigger?

Trigger --> Function_A --> Function_B

--Basil Bourque

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Basil Bourque (#1)
Re: Can a nested function determine it is being called within a trigger?

Basil Bourque <basil.list@me.com> writes:

When a trigger calls a function, that function can determine if it is being called from within a trigger by testing for a value in the special variable "TG_OP".

Uh, no, not really. TG_OP is a local variable in the trigger function;
it's not visible from elsewhere.

But what if a trigger calls a function that calls a 2nd function via the "PERFORM" command? Can that 2nd function tell if it is being run in a trigger?

No. Doesn't really matter whether you use PERFORM or not.

regards, tom lane

#3Rob Sargent
robjsargent@gmail.com
In reply to: Tom Lane (#2)
Re: Can a nested function determine it is being called within a trigger?

On 04/15/2011 05:36 PM, Tom Lane wrote:

Basil Bourque<basil.list@me.com> writes:

When a trigger calls a function, that function can determine if it is being called from within a trigger by testing for a value in the special variable "TG_OP".

Uh, no, not really. TG_OP is a local variable in the trigger function;
it's not visible from elsewhere.

But what if a trigger calls a function that calls a 2nd function via the "PERFORM" command? Can that 2nd function tell if it is being run in a trigger?

No. Doesn't really matter whether you use PERFORM or not.

regards, tom lane

One could pass a boolean from function A to B, I suppose.