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

From darcy@druid.net (D'Arcy J.M. Cain)
Subject Re: Changes to functions and triggers
Date
Msg-id m1357Vu-000AY6C@druid.net
Whole thread Raw
In response to Changes to functions and triggers  (darcy@druid.net (D'Arcy J.M. Cain))
List pgsql-hackers
Thus spake Zeugswetter Andreas
> > darcy@druid.net (D'Arcy J.M. Cain) writes:
> > >     nargs = trigger->tgnargs;
> > >     if (nargs != 4)
> > >         elog(ERROR, "make_date (%s): %d args", relname, nargs);
> 
> The simple answer is, that your procedure does not take four arguments.
> The old and new tuple are passed implicitly to your procedure,
> they don't show up in the argument list.

Right.  That's why the function takes void as its parameter list.  (I hadn't
shown that in my message.)  The code above finds the args from the global
environment.

In fact, my problem was, I think, that I needed to use the SPI_connect() and
SPI_finish() functions which I don't think were available when I first wrote
the function.  I added those, recompiled and all now works.  It just took
me a while to realize that the problem was in the C code and not the SQL
statements to use it.

> This is also the reason your code works if you add four "dummy" string 
> arguments (you can test that by supplying random values not the column names
> in your create trigger statement).

Nope.  Without the fix above it didn't work no matter what I tried.

Thanks for everyone's help.  Now I can move on to the operator defining
problem but that's a subject for another message.

It's funny but the two areas inthe new version that I am having trouble
with are the two that I originally helped document.  :-)

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


pgsql-hackers by date:

Previous
From: Giles Lean
Date:
Subject: Re: Big 7.1 open items
Next
From: Bruce Momjian
Date:
Subject: Re: Big 7.1 open items