Re: Triggers on columns - Mailing list pgsql-hackers

From James Pye
Subject Re: Triggers on columns
Date
Msg-id C3B0F6DC-50B7-495C-8ED3-33401ACD01BE@jwp.name
Whole thread Raw
In response to Re: Triggers on columns  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-hackers
On Sep 8, 2009, at 7:38 AM, Kevin Grittner wrote:

> David Fetter <david@fetter.org> wrote:
>
>> CREATE TRIGGER trig BEFORE UPDATE ON tbl FOR EACH ROW
>>    WHEN (NEW.col IS DISTINCT FROM OLD.col)
>>        EXECUTE PROCEDURE trigger_func();
>
> How much does that buy you versus including this at the start of
> trigger_func:

On the face, it buys nothing, IMO. ISTM, looking at the examples, that  
the above syntax would lead to redundant logic if the particular  
trigger_func() were used by multiple TRIGGERs. That is, assuming the  
precondition is necessary for proper functionality, it would have to  
be repeated on all the TRIGGERs that trigger_func() would be executed  
by.

[..moving away from the isolated use-case of the example]

However, if trigger_func() were a generalized trigger function, which  
would likely be the case if it were used by multiple TRIGGERs[;)]. The  
necessary precondition would probably be inconsistent across the  
TRIGGERs, and thus the feature could be quite useful.
Currently, such a generalized trigger function *could* be crafted  
using trigger arguments, but I'd be inclined to think that that would  
require more exercise than it would be worth( that is, I'm imagining  
something that would be dirty, and much less convenient than WHEN =).


Personally, I think WHEN () would be pretty sweet. =)


pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: CTE bug?
Next
From: Robert Haas
Date:
Subject: Re: Triggers on columns