Re: Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>
Cc: PostgreSQL Mailing List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement
Date: 2002-10-24 13:42:46
Message-ID: 11292.1035466966@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-sql

Ludwig Lim <lud_nowhere_man(at)yahoo(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Papa 2002-10-24 13:57:51 heap_blks_hit and heap_blks_read
Previous Message Jan Bessels 2002-10-24 13:16:30 Problem: psql -c works but psql -f fails when executed from a Perl script using system().

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-10-24 14:23:29 Re: Using the same condition twice
Previous Message Hosen, John 2002-10-24 12:19:02 Re: 'epoch'::timestamp and Daylight Savings

Browse pgsql-sql by date

  From Date Subject
Next Message Charles H. Woloszynski 2002-10-24 14:27:22 Help on creating a High Availability PostgreSQL solution?
Previous Message Zuev Dmitry 2002-10-24 11:35:21 How can I retrieve an info about function arguments ?