Re: possible to lock a single row in table?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Bruno Boettcher <bboett(at)erm1(dot)u-strasbg(dot)fr>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: possible to lock a single row in table?
Date: 2001-06-20 16:43:37
Message-ID: Pine.BSF.4.21.0106200939170.97582-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Wed, 20 Jun 2001, Bruno Boettcher wrote:

> i have a lots of threads that work on a table, making insertions,
> updates removes.....
>
> now i certain cases its important to keep data integrity, so i looked
> into locks....

What kind of data integrity are you trying to implement?

> all i found was a lock function that locks the entire table....
>
> now even in shared mode, if i understand it well this means that as long
> as the locking procedure isn't finished, no other thread can update or
> delete data, right? Thats really harsh, since there are really an awful
> lot of threads....
>
> isn't it possible to lock only a specific row?

Yes. Look at SELECT ... FOR UPDATE. That should lock those rows
matched such that another transaction that attempts to select for update,
update or delete those rows waits until the locking transaction finishes.

> and what happens to other insert queries whilst the lock is operational?
> Are they postponed and the valling thread waits, or does the call return
> with an error?

IIRC, postponed until the transaction that made the lock commits or
rolls back.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Hunter, Ray 2001-06-20 16:45:20 Functions and Triggers
Previous Message Peter Eisentraut 2001-06-20 15:54:02 Re: possible to lock a single row in table?