Re: Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement - Mailing list pgsql-sql

From Tom Lane
Subject Re: Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement
Date
Msg-id 11292.1035466966@sss.pgh.pa.us
Whole thread Raw
In response to Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement  (Ludwig Lim <lud_nowhere_man@yahoo.com>)
Responses Problem: Referential Integrity Constraints lost
List pgsql-sql
Ludwig Lim <lud_nowhere_man@yahoo.com> writes:
>   Is there a way to emulate a SELECT..FOR UPDATE to
> series of LOCK/SELECT statement.

No.  LOCK can only acquire table-level locks; the point of SELECT FOR
UPDATE is to acquire row-level locks.

>    I am surprised because according to the docs
> (version 7.2), it says:
>     ROW SHARE MODE  
>     Note: Automatically acquired by SELECT ... FOR
> UPDATE. 

SELECT FOR UPDATE gets a table-level lock just to ensure that the table
doesn't disappear from under it while it's doing its scan.  The ROW
SHARE lock is pretty weak though, and doesn't block anything less
drastic than DROP/ALTER TABLE or VACUUM FULL.

The 7.3 development docs are perhaps clearer about this; try
http://developer.postgresql.org/docs/postgres/explicit-locking.html
        regards, tom lane


pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: ORDER the result of a query by date
Next
From: "Charles H. Woloszynski"
Date:
Subject: Help on creating a High Availability PostgreSQL solution?