Louis-David Mitterrand <cunctator@apartia.ch> writes:
>> May we see the C trigger? I'm suspicious it's doing something wrong...
> Please find the trigger attached to this message
Although I don't see an obvious connection to the error message you are
getting, I am suspicious that the problem happens because you are
expecting CurrentTriggerData to stay valid throughout the execution of
your trigger --- through executions of sub-queries, in fact.
CurrentTriggerData is a global and should be considered extremely
volatile, because it will get changed if any other trigger is fired
by the sub-query, and may get zeroed anyway if certain paths through
the function manager get taken.
I recommend this coding pattern for user-defined triggers:
1. Copy CurrentTriggerData into a local variable, say
TriggerData *trigdata;
*immediately* upon entry to your trigger function, and then reset
CurrentTriggerData = NULL before doing anything else.
2. Subsequently, use "trigdata" not CurrentTriggerData.
Aside from not causing problems for recursive trigger calls, this
approach will also be a lot easier to convert to 7.1 code --- a word
to the wise eh?
If you still see flaky behavior after making this change, please let me
know and I'll probe more deeply.
regards, tom lane