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


Fri, 13 Aug 2004 13:25:19 +0200
Thomas Hallgren <thhal@mailblocks.com>
Trigger function returning null
Thomas Hallgren <thhal@mailblocks.com> 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

Fri, 13 Aug 2004 10:02:12 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Trigger function returning null 
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



Fri, 13 Aug 2004 18:08:53 +0200
Thomas Hallgren <thhal@mailblocks.com>
Re: Trigger function returning null
Thomas Hallgren <thhal@mailblocks.com> 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 <symbol>NULL</> or a
<     <structname>HeapTuple</> pointer.  Be careful to return either
---
>     A trigger function must return either a
>     <structname>HeapTuple</> pointer or a <symbol>NULL</> pointer
>     (<emphasis>not</> a SQL NULL, that is, do not set isNull true).
>     Be careful to return either

			regards, tom lane

Fri, 13 Aug 2004 12:18:50 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Trigger function returning null 