Re: a primer on trigger? - Mailing list pgsql-general

From Stephan Szabo
Subject Re: a primer on trigger?
Date
Msg-id Pine.BSF.4.21.0105041152140.60613-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: a primer on trigger?  (Joel Burton <jburton@scw.org>)
List pgsql-general
On Fri, 4 May 2001, Joel Burton wrote:

> Hmmm... this raises an interesting question.
>
> Would it be possible to hook into (via trigger or other mechanism) so that
> we could execute a function on commit? There are PG triggers to do things
> like send email, etc., which, yes, can't be undone if the transaction
> ultimately fails. Instead, could we:
>
> 1) have a trigger that (in this case) instead of sending email, just adds
> the information to an 'email-to-send' table.
>
> 2) commit the transaction
>
> 3) the trigger TRANSACTION_AFTER is called, and from that, we can scan the
> table, and actually do some of these system calls?
>
> Can this be done? Is this terrible design? Is there any other reasonable
> way to handle things like this?

Probably could be done, but the question would be what happens if the
TRANSACTION_AFTER raises an error condition for whatever reason?  You
can't go back and un-commit the transaction.

For that case above, you'd probably be better off having something in cron
or whatever looking at your email-to-send table since it'll get only those
things that have already committed.  You could put all the logic in a
function on the server still.


pgsql-general by date:

Previous
From: "Brian Z"
Date:
Subject: Primary Keys
Next
From: Stephan Szabo
Date:
Subject: Re: a primer on trigger?