Triggers per transaction, workaround? prospects? - Mailing list pgsql-general

From Karl O. Pinc
Subject Triggers per transaction, workaround? prospects?
Date
Msg-id 20040228143808.E20755@mofo.meme.com
Whole thread Raw
Responses Re: Triggers per transaction, workaround? prospects?  (Gregory Wood <gwood@ewebengine.com>)
List pgsql-general
Hi,

I don't suppose that the todo item:

Referential Integrity
   o Add deferred trigger queue file (Jan)

Means that there will be a statement like:

CREATE TRIGGER ... FOR EACH TRANSACTION

?

I frequently encounter situations where the
database is only 'good' when all the the statements
in the transaction have completed.  (Duh, isn't this
the _point_ of transactions?)  The latest is I want
a per foreign key sequence number column, 1, 2, 3, etc., say,
a per-person counter, which must not contain any 'gaps'.  I can do this
so long as nobody every makes any mistakes
in sequencing, but once the sequence numbers are in place
there's no way to re-order the rows in a sequence
(the rows belonging to one person) without deleting
and re-creating all the rows with sequence numbers
> = the first mis-placed sequence number.  Given the
existance of other rows which reference the sequenced rows,
this is not a pretty picture.  It'd be nice to be able to
put a series of UPDATE statements in a transaction
and have a trigger check the state of the database when the
transaction commits.  (And be able to raise an exception
if the rules are violated.)

Has anybody else encountered problems like this and come up
with any solutions?

Stupid question:
If triggers automatically created to support REFERENCES
constraints can be deferred to execute on transaction commit,
and see the results of the statements executed prior to
the COMMIT, then why can't this be done for regular
triggers?

Regards,

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                   -- Robert A. Heinlein


pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Copying data from one table to another
Next
From: Andrew Sullivan
Date:
Subject: gborg not responding?