Trigger function returning null

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

Trigger function returning null

От:
Thomas Hallgren <thhal@mailblocks.com>
Дата:
In backend/commands/trigger.c the following can be found:
    /*     * Trigger protocol allows function to return a null pointer,     * but NOT to set the isnull result flag.     */    if (fcinfo.isnull)        ereport(ERROR,

Why?

Regards,

Thomas Hallgren


Re: Trigger function returning null

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Hallgren  writes:
> In backend/commands/trigger.c the following can be found:
>      /*
>       * Trigger protocol allows function to return a null pointer,
>       * but NOT to set the isnull result flag.
>       */
>      if (fcinfo.isnull)
>          ereport(ERROR,

> Why?

Why not?

The real answer is "it's historical and I didn't see any need to
change it".  But one could argue that a function returning NULL
doesn't know it's supposed to be a trigger.
		regards, tom lane

Re: Trigger function returning null

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Hallgren  writes:
> Perhaps you should either change this behavior or make a note it in 
> "Writing Trigger Functions in C"?

Okay, I've changed the text thusly:

diff -r1.35 trigger.sgml
434,435c434,437
<     A trigger function must return either NULL</> or a
<     HeapTuple</> pointer.  Be careful to return either
---
>     A trigger function must return either a
>     HeapTuple</> pointer or a NULL</> pointer
>     (not</> a SQL NULL, that is, do not set isNull true).
>     Be careful to return either
		regards, tom lane

Re: Trigger function returning null

От:
Thomas Hallgren <thhal@mailblocks.com>
Дата:
Tom Lane wrote:

>Why not?
>
>The real answer is "it's historical and I didn't see any need to
>change it".  But one could argue that a function returning NULL
>doesn't know it's supposed to be a trigger.
>  
>
The reason I ask is that this behavior just bit me in PL/Java. Triggers 
returning null didn't work. I've fixed it at my end by simply forcing 
the isnull to false for triggers. I just wanted to know if there was 
some deeper thought behind this that could result in side effects.

Perhaps you should either change this behavior or make a note it in 
"Writing Trigger Functions in C"? Even if the documented example use a 
local isnull, it's not evident that you have to do that.

Regards,

Thomas Hallgren



FAQ