Re: Row Lock

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Andreas Prohaska <ap(at)apeiron(dot)de>
Cc: 'Alessandro Polverini' <polverini(at)nibbles(dot)it>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Row Lock
Date: 2003-10-07 15:03:51
Message-ID: 1065539031.1619.8.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Tue, 2003-10-07 at 10:27, Andreas Prohaska wrote:
> I don't think that there is something similar in postgres. You would have
> to do this on your own, using an "int" or "postgres timestamp". What I
> meant was something like:
>
> 1. Read the row from the database together with the optimistic
> control
> column (occ). Let's assume it's an int with a current value of 1.
>
> 2. Remember this value (1) and let the user edit the record.
>
> 3. Now before writing the changes of the user into the database:
>
> 3.a SELECT the row FOR UPDATE and compare the current value
> of the occ with the value you remembered. If they are
> not equal -> rollback, otherwise ...
>
> 3.b increment the value of the occ to 2
>
> 3.c UPDATE the record (releasing the update lock)
>
>
> As Dave Cramer suggested you may also use a timestamp with a
> trigger to do this automatically. Although I don't know if there
> wouldn't be a theoretical possibility that someone updates the
> record again before the trigger runs (I really don't know!).
No, this isn't possible. The timestamp column with an update/insert
trigger will work correctly.
>
> > > The easiest way to come around this sort of problem is to use an
> > > optimistic control column (like an int) that is incremented
> > > with every row update. This allows you to detect changes by other
> > > users before making your own.
> >
> > I'm not really sure what do you mean with the use of
> > optimistic control
> > column, can you please give me some detail?
> >
> > The problem (for me) is to find a solution that is functional also for
> > clients that uses the db other the mine.
> >
> > In mysql there is the column type "timestamp" that does exactly this:
> > records the time of the last update of the row, so I need to
> > check only
> > this value.
> >
> > Is there something similar in postgresql?
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Dave Cramer <Dave(at)micro-automation(dot)net>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Xavier Poinsard 2003-10-08 11:36:30 Problem with bytea getBytes and setBytes
Previous Message Dave Cramer 2003-10-07 14:29:35 Re: Row Lock