Triggers per transaction, workaround? prospects?

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Triggers per transaction, workaround? prospects?
Date: 2004-02-28 20:38:08
Message-ID: 20040228143808.E20755@mofo.meme.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2004-02-28 20:40:06 Re: PLSQL Question regarding multiple inserts
Previous Message Richard Huxton 2004-02-28 16:40:26 Re: Copying data from one table to another