Re: will I need nested transactions ?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: will I need nested transactions ?
Date: 2004-05-17 16:26:46
Message-ID: 40A8E7C6.9060004@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andreas wrote:
> Hi,
>
> will I need "nested transactions" which - as I read - aren't
> implemented, yet ?
>
> I have some objects that rely on each other.
> Each has a status like proposal, working, canceled.
>
> table-A <--- table-B <--- table-C <--- table-D
>
> Those are (1, OO) relationships,
> A status change above gets cascaded down but not upwards.
> If I try to cancel a table-A-record every "lower" record in B, C, D
> should be canceled, too, when the transaction is committed.
> Since it is possible, that I cancel e.g. a table B object only its
> children should get updated but not table-A.
>
> I thought somthing along this to cancel a type B object:
>
> BEGIN
> BEGIN
> BEGIN
> UPDATE table-D
> END
> if no error UPDATE table-C
> END
> if no error UPDATE table-B
> END
>
> Does this make sense and will it provide the necesary protection ?

I don't think it needs to be that complicated. Just wrap the whole lot
in one transaction and it will either all work or all fail:

BEGIN
UPDATE table_d ...
UPDATE table_c ...
UPDATE table_d ...
COMMIT;

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ben 2004-05-17 16:55:02 Re: will I need nested transactions ?
Previous Message David Siegal 2004-05-17 15:29:10 Run external program upon change