Bug #722: SELECT FOR UPDATE bug
Pablo Aviles
27/07/2002 10:58
To: Tom Lane <tgl@sss.pgh.pa.us>
cc:
Subject: Re: [BUGS] Bug #722: SELECT FOR UPDATE bug
Hi,
we are use Postgresql 7.3.
The case in questions is: we have many clients (pc's) of postgresql. Every
client try to block an employee to display at user. The user make change
in the employee, but nobody can take the same employee at same time.
Before changes, the next step is update the record (Record blocked)
But, when I use
SELECT * FROM employees
WHERE status = 'A'
LIMIT 1
FOR UPDATE;
to catch the employee, only the first user select a record. Other users
can`t select any employee until the first user release the record. The
first conclusion here, is that Postgresql block all employee table.
When we try to use the LOCK sentence, the result don´t have change.
regards,
Pablo Avilés Cisneros
Technology, ITS
Software Development Area
Technology, ITS
San José, Costa Rica
email: paviles@its.co.cr
Tom Lane <tgl@sss.pgh.pa.us>
27/07/2002 09:58
To: paviles@its.co.cr, pgsql-bugs@postgresql.org
cc:
Subject: Re: [BUGS] Bug #722: SELECT FOR UPDATE bug
pgsql-bugs@postgresql.org writes:
SELECT * FROM employees
WHERE status = 'A'
LIMIT 1
FOR UPDATE;
The problem, in the previous sentence, is block every record on
employees, although we want one record, we want limit 1.
I do not believe that. Could you give a more complete example of
your problem?
It would also help if you'd state which Postgres version you're using.
regards, tom lane
On Fri, 26 Jul 2002 paviles@its.co.cr wrote:
Pablo Aviles
27/07/2002 10:58To: Tom Lane <tgl@sss.pgh.pa.us>
cc:
Subject: Re: [BUGS] Bug #722: SELECT FOR UPDATE bugHi,
we are use Postgresql 7.3.
The case in questions is: we have many clients (pc's) of postgresql. Every
client try to block an employee to display at user. The user make change
in the employee, but nobody can take the same employee at same time.
Before changes, the next step is update the record (Record blocked)But, when I use
SELECT * FROM employees
WHERE status = 'A'
LIMIT 1
FOR UPDATE;to catch the employee, only the first user select a record. Other users
can`t select any employee until the first user release the record. The
If you use that same query in two transactions of course it's going to
block, they're almost certainly going to try to get the same record and
the second'll block since the first already has the lock.
When I do the following:
sszabo=# create table employee(name text, status char(1));
CREATE TABLE
sszabo=# insert into employee('a', 'a');
ERROR: parser: parse error at or near "'a'"
sszabo=# insert into employee values('a', 'a');
INSERT 8567431 1
sszabo=# insert into employee values('b', 'a');
INSERT 8567432 1
sszabo=# insert into employee values('c', 'b');
INSERT 8567433 1
Transaction 1:
begin;
sszabo=# select * from employee where status='a' for update limit 1;
name | status
------+--------
a | a
(1 row)
Transaction 2:
sszabo=# begin;
BEGIN
sszabo=# select * from employee where status='a' and name='b' for update
limit 1;
name | status
------+--------
b | a
(1 row)
Whereas running the same query in both causes the second to block until
the first finishes. If I update the first transaction's row in that
transaction so that it doesn't match, the second query doesn't return
anything, which might be a bug however (I'm not sure what should
happen in that case)