From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | <paviles(at)its(dot)co(dot)cr> |
Cc: | <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: Bug #722: SELECT FOR UPDATE bug |
Date: | 2002-07-29 13:59:24 |
Message-ID: | 20020729065514.X92453-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Fri, 26 Jul 2002 paviles(at)its(dot)co(dot)cr wrote:
> Pablo Aviles
> 27/07/2002 10:58
>
>
> To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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
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)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-07-29 14:26:19 | Re: Money locale currency symbol position |
Previous Message | Tatsuo Ishii | 2002-07-29 13:35:15 | Re: Multi-byte character bug |