From: | "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk> |
---|---|
To: | Markus Wagner <wagner(at)imbei(dot)uni-mainz(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org, pgsql-odbc(at)postgresql(dot)org |
Subject: | Re: row-level locking |
Date: | 2003-04-01 11:36:23 |
Message-ID: | Pine.LNX.4.21.0304011232160.2573-100000@ponder.fairway2k.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-odbc |
On Tue, 1 Apr 2003, Markus Wagner wrote:
> Hi,
>
> we need to prevent write access for a single row of a table for a short time.
>
> We found a short description for the "SELECT FOR UPDATE" statement:
> "perform exclusive locking of selected rows"
>
> Now my question: Is this a good method for our purpose?
>
> Assuming that we lock our row with
> "SELECT FOR UPDATE FROM <table> WHERE <our condition>",
> how can we unlock it later?
The syntax is: SELECT * FROM <table> ... FOR UPDATE
(just saving you that error message)
> Do we have to put the whole thing in a transaction (which may be tricky from
> within a VB-Application...)?
Yes, it locks the selected rows for the duration of the surrounding
transaction. Therefore, you need to be in a transaction when you issue the
SELECT and you can only release the lock by commiting or rolling back.
If you're using 7.3+ you might want to look at the AUTOCOMMIT setting/mode. I
believe that was added for the 7.3 release and it will enable you to avoid
issuing the BEGIN explicitly, although obviously you still need the COMMIT or
ROLLBACK.
>
> Thanks a lot,
> Markus
>
--
Nigel J. Andrews
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Wagner | 2003-04-01 11:36:41 | row-level locking |
Previous Message | Jean-Christian Imbeault | 2003-04-01 11:24:10 | Re: row-level locking |
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Wagner | 2003-04-01 11:36:41 | row-level locking |
Previous Message | Jean-Christian Imbeault | 2003-04-01 11:24:10 | Re: row-level locking |