Re: Transaction vs. Savepoints

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Transaction vs. Savepoints
Date: 2007-02-09 16:21:59
Message-ID: 896.1171038119@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Andreas <maps(dot)on(at)gmx(dot)net> writes:
> A interactive application on the other hand would open records and have
> them in an edit-form as long as the user needs them.
> Probaply I just don't get it how to use transactions in such a
> interactive scenario the right way.

Right, a lot of novices think they should hold open a transaction for
the whole edit cycle. This is not good design: what if the user goes
off to lunch and meanwhile someone else wants to edit the same record?

Usually the best approach is to fetch the data without acquiring any
lock, allow the interactive editing to happen outside a transaction,
then when the user hits SAVE, perform a transaction that locks the
row(s), checks for conflicting changes, and commits if no conflict.
On conflict you might be able to resolve the discrepancy automatically,
but if not, you just fail and let the user deal with it ...

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2007-02-09 16:42:38 Re: relation 12345 is still open
Previous Message Andreas 2007-02-09 15:58:30 Re: Transaction vs. Savepoints