Обсуждение: New/old style trigger API

Поиск
Список
Период
Сортировка

New/old style trigger API

От
darcy@druid.net (D'Arcy J.M. Cain)
Дата:
The docs seem a little sketchy but the source implies that there is
a difference between new and old style triggers.  I can't seem to find
this difference.  I tried following the only current example I could
find but I get a core dump.  Here is the backtrace.

#0  0x0 in ?? ()
#1  0x8136052 in fmgr_oldstyle (fcinfo=0xbfbfd134) at fmgr.c:433
#2  0x80b6b2d in ExecCallTriggerFunc (trigger=0x82ce030, trigdata=0xbfbfd1c8,    per_tuple_context=0x827acf0) at
trigger.c:865
#3  0x80b6e15 in ExecBRUpdateTriggers (estate=0x82fbf50, tupleid=0xbfbfd264,    newtuple=0x83094a8) at trigger.c:1008
#4  0x80bcf3a in ExecReplace (slot=0x8308018, tupleid=0xbfbfd264,    estate=0x82fbf50) at execMain.c:1416
#5  0x80bcc82 in ExecutePlan (estate=0x82fbf50, plan=0x82fbec8,    operation=CMD_UPDATE, numberTuples=0,
direction=ForwardScanDirection,   destfunc=0x83092f0) at execMain.c:1127
 
#6  0x80bc27b in ExecutorRun (queryDesc=0x8307cc0, estate=0x82fbf50,    feature=3, count=0) at execMain.c:233
#7  0x80ff29b in ProcessQuery (parsetree=0x82f6e20, plan=0x82fbec8,    dest=Remote) at pquery.c:277
#8  0x80fddd3 in pg_exec_query_string (   query_string=0x82f6030 "UPDATE bgroup SET actypid = 1,ddate = NULL,edate =
'2001-07-23',mail= '',ftp = '',dns = 'f',bname = 'jpsantos',bgdesc = '',isp = 'VEX',pdate = '2001-04-23',pmon =
5,bgroup_active= 't',sdate = '1999-"...,    dest=Remote, parse_context=0x827a720) at postgres.c:808
 
#9  0x80fedd1 in PostgresMain (argc=4, argv=0xbfbfd4c8, real_argc=9,    real_argv=0xbfbfdc54, username=0x826325d
"darcy")at postgres.c:1905
 
#10 0x80ea2ad in DoBackend (port=0x8263000) at postmaster.c:2114
#11 0x80e9eb2 in BackendStartup (port=0x8263000) at postmaster.c:1897
#12 0x80e91aa in ServerLoop () at postmaster.c:995
#13 0x80e8b7c in PostmasterMain (argc=9, argv=0xbfbfdc54) at postmaster.c:685
#14 0x80caff4 in main (argc=9, argv=0xbfbfdc54) at main.c:175
#15 0x806bc81 in ___start ()

It gets to fmgr_oldstyle() and then dies from a jump to a null pointer.
Can someone please tell me how to make my function a newstyle one.  I
will update the docs once I have it working.

-- 
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.


Re: New/old style trigger API

От
Tom Lane
Дата:
darcy@druid.net (D'Arcy J.M. Cain) writes:
> It gets to fmgr_oldstyle() and then dies from a jump to a null pointer.
> Can someone please tell me how to make my function a newstyle one.

Perhaps you forgot the PG_FUNCTION_INFO_V1 declaration?  See
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/trigger-examples.html
        regards, tom lane


Re: New/old style trigger API

От
darcy@druid.net (D'Arcy J.M. Cain)
Дата:
Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> > It gets to fmgr_oldstyle() and then dies from a jump to a null pointer.
> > Can someone please tell me how to make my function a newstyle one.
> 
> Perhaps you forgot the PG_FUNCTION_INFO_V1 declaration?  See
> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/trigger-examples.html

Yah, I was looking at chapter 22 on SPI programming.  I assume that the
same should apply there.  Shall I go ahead and add it to the docs in that
chapter as well?

I wonder if there is a relation to another problem I am having.  On AIX
I can compile my chkpass function (in contrib which I just updated) OK
but when I use it I get a similar core dump there that I don't see on
NetBSD.  Does it require the same interface?  Shall I update those pages
as well?

BTW, here is the link command I needed to get as far as I did.
   ld -G -o $@ $< -bexpall -bnoentry -lc

-- 
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.


Re: New/old style trigger API

От
Tom Lane
Дата:
darcy@druid.net (D'Arcy J.M. Cain) writes:
> Yah, I was looking at chapter 22 on SPI programming.  I assume that the
> same should apply there.  Shall I go ahead and add it to the docs in that
> chapter as well?

Uh ... where?  I see nothing related to trigger programming in chapter 22.
There's an example of an old-style function at
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/spi-examples.html
but it's not a trigger.
        regards, tom lane


Re: New/old style trigger API

От
darcy@druid.net (D'Arcy J.M. Cain)
Дата:
Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> > Yah, I was looking at chapter 22 on SPI programming.  I assume that the
> > same should apply there.  Shall I go ahead and add it to the docs in that
> > chapter as well?
> 
> Uh ... where?  I see nothing related to trigger programming in chapter 22.
> There's an example of an old-style function at
> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/spi-examples.html
> but it's not a trigger.

Ah.  So PG_FUNCTION_INFO_V1() is strictly for triggers then.  The name
suggested it was a little more global than that.

-- 
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.


Re: New/old style trigger API

От
Tom Lane
Дата:
darcy@druid.net (D'Arcy J.M. Cain) writes:
>> There's an example of an old-style function at
>> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/spi-examples.html
>> but it's not a trigger.

> Ah.  So PG_FUNCTION_INFO_V1() is strictly for triggers then.

No, it's for new-style functions.  See
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/xfunc-c.html
        regards, tom lane


Re: New/old style trigger API

От
darcy@druid.net (D'Arcy J.M. Cain)
Дата:
Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> >> There's an example of an old-style function at
> >> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/spi-examples.html
> >> but it's not a trigger.
> 
> > Ah.  So PG_FUNCTION_INFO_V1() is strictly for triggers then.
> 
> No, it's for new-style functions.  See
> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/xfunc-c.html

I'm so confused.  :-)

OK, so all functions can be upgraded to version 1 calling sequence, not
just ones used for triggers.  I think I have it but the docs could still
use some work.  If someone wants to check out the latest version of my
chkpass function in contrib and let me know if I seem to have the right
idea now then I will go ahead and try to improve the docs.

-- 
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.


Re: New/old style trigger API

От
Tom Lane
Дата:
darcy@druid.net (D'Arcy J.M. Cain) writes:
> OK, so all functions can be upgraded to version 1 calling sequence, not
> just ones used for triggers.

Now you're getting there.  Actually triggers *must* be upgraded to the
new calling sequence, because we don't support old-style triggers
anymore.  But for other functions it's optional.
        regards, tom lane


Re: New/old style trigger API

От
darcy@druid.net (D'Arcy J.M. Cain)
Дата:
Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> > OK, so all functions can be upgraded to version 1 calling sequence, not
> > just ones used for triggers.
> 
> Now you're getting there.  Actually triggers *must* be upgraded to the
> new calling sequence, because we don't support old-style triggers
> anymore.  But for other functions it's optional.

OK, I am going to try to find time to update the other pages.  In particular
I will update the examples and add the list of macros.

-- 
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.