Re: Changes to functions and triggers - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Changes to functions and triggers
Date
Msg-id 6191.961625231@sss.pgh.pa.us
Whole thread Raw
In response to Re: Changes to functions and triggers  (darcy@druid.net (D'Arcy J.M. Cain))
List pgsql-hackers
darcy@druid.net (D'Arcy J.M. Cain) writes:
> I must have done this wrong.  The actual error I get when I start from
> scratch is this:
> ERROR:  make_date (bgroup): 0 args

> That message comes from my program at the start of the function.

>      [ blah blah blah ]

>     trigger = CurrentTriggerData->tg_trigger;

>     nargs = trigger->tgnargs;
>     if (nargs != 4)
>         elog(ERROR, "make_date (%s): %d args", relname, nargs);

Hmm.  Not sure if this is the root of the problem or not, but it's
*real* dangerous to assume that the global CurrentTriggerData stays
set (the same way!) throughout your function.  You should copy
CurrentTriggerData into a local TriggerData * variable immediately
upon being called and then just use that variable.  I wonder if you
could be losing because some other trigger is getting invoked before
your routine returns...

CurrentTriggerData doesn't even exist anymore in current sources,
so doing it that way will also ease the pain of updating to 7.1 ;-)

Another thing to keep in mind is that the data structures pointed to
by CurrentTriggerData had better be treated as read-only.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: limit?
Next
From: "Randall Parker"
Date:
Subject: tablespace managed by system vs managed by database