Re: Update aborted if trigger function fails?

From: Carlos Moreno <moreno(at)mochima(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Update aborted if trigger function fails?
Date: 2005-04-12 14:55:30
Message-ID: 425BE162.6010501@mochima.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Huxton wrote:

>> I just noticed this (odd?) behaviour, and it kind of
>> scares me.
>
>> Isn't this a little fragile? Is there something I
>> could do to avoid this situation? Should trigger
>> functions be extremely simple as to guarantee that
>> an error would never happen?
>
> There's nothing else it can do, really. Far better that the whole update
> fails than you get an inconsistent database.
>
> Imagine you have a banking system, and every time you add a row to the
> transaction-history, you update the "current_balance" table. Which would
> you prefer, both updates fail, or the two get out of sync?

Yes, you are absolutely correct.

I guess the concern came up as result of a particular
situation, in which failing to properly process the
trigger function is not that crucial (I wanted to
update some additional information that is "optional",
and that can be reconstructed easily after discovering
that the trigger function had been failing). But in
our case, failing to complete the update is rather
critical (things can be reconstructed but under certain
conditions only, and only by temporarily shutting down
the system for a few minutes).

So, I was thinking that there may be a way for the user
to instruct PG to ignore the fact that the trigger
function failed -- that way, we would overcome the
difficulties that you mention in improving dependency
checking when functions are involved -- PG wouldn't have
to determine it: the user would tell it.

> So - how do you deal with this? Well, you test.

Fair enough.

Thanks!

Carlos
--

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2005-04-12 15:17:21 Re: Update aborted if trigger function fails?
Previous Message Scott Marlowe 2005-04-12 13:55:23 Re: Getting the output of a function used in a where clause