Re: Triggers on columns

From: James Pye <lists(at)jwp(dot)name>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: "David Fetter" <david(at)fetter(dot)org>, "Itagaki Takahiro" <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Triggers on columns
Date: 2009-09-08 21:02:40
Message-ID: C3B0F6DC-50B7-495C-8ED3-33401ACD01BE@jwp.name
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sep 8, 2009, at 7:38 AM, Kevin Grittner wrote:

> David Fetter <david(at)fetter(dot)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. =)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-09-08 21:22:09 Re: Triggers on columns
Previous Message David Fetter 2009-09-08 20:15:03 CTE bug?