How does "SELECT ... FOR UPDATE" work?

From: Joshua Daniel Franklin <joshua(at)iocc(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How does "SELECT ... FOR UPDATE" work?
Date: 2002-11-22 15:13:19
Message-ID: Pine.LNX.4.44.0211220853480.21521-100000@iocc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-novice

I am trying to build a small multiuser application.
The single-user mode works fine, but I want to be able
to lock some rows that are going to be updated.

I am trying to understand how to use "SELECT ... FOR UPDATE;"
to do this. With the psql client, I opened two sessions and did

"select * from iocc where id='100' for update;"

which returned the appropriate row. Then, in the *other* session,

"update iocc set zip = '71998' where id = '100';"

which returned "UPDATE 1" (I was expecting some error). I then
looked back in the first session and the row was indeed updated.
Obviously I'm missing something here.

I'm using RedHat 7.3 with postgresql-server-7.2.1-5 rpm.
Thanks.

Joshua Daniel Franklin
IOCC.COM

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nic Ferrier 2002-11-22 15:15:18 Re: streaming result sets: progress
Previous Message Vinni 2002-11-22 02:02:47 Problem

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2002-11-22 15:18:06 Re: Viewing Foreign key constraints in psql
Previous Message HK 2002-11-22 11:44:26 how to know backend crashed ??