Re: unlimited undo/journaling

From: "Glen Parker" <glenebob(at)nwlink(dot)com>
To: "Pg-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: unlimited undo/journaling
Date: 2002-06-26 20:52:05
Message-ID: 004101c21d53$54ec5260$0b01a8c0@johnpark.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > so what i want is basically an unlimited undo or journalling feature
> > for more or less every field.
> >
> > the idea should be to save the data-difference in some journalling
> > table, but i'm not sure how this could be done properly. maybe
> > somebody with some experience can help me here ?
>
> Perhaps the simplest system is to have two tables: address
> and arc_address.
> Use "before" triggers on address to copy the old data into
> arc_address and
> stamp it with a version number/timestamp.
>
> I've done something similar to this using a sequence to
> generate unique
> version numbers for me.

I have too, but not using a sequence, but instead another table for
version numbers:
Create table trans_version (trans_id int4, version int4);

Copying the current data into the archive table is quick and efficient
with this method:
Create table mytrans(trans_id int4, date_modified timestamp, ...);
Create table arch_mytrans(version int4, trans_id int4, date_modified
timestamp, ...);

Then, when modifying a document:
Begin;
Insert into arch_mytrans select <new version #>, * from mytrans where
transi_d = <trans id>;
Update trans_version set version=<new version #> where trans_id = <trans
id>;
Commit;

This allows you to add more fields to your tables without messing with
your versioning code.

Glen Parker
glenebob(at)nwlink(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carl Meyer 2002-06-26 20:52:46 Re: unlimited undo/journaling
Previous Message Chris Humphries 2002-06-26 20:46:36 plpython escape builtin method?