Ken Godee wrote:
I hope I can explain what I'm trying to do....
I worked this out with psql first and now trying to
get it to work with psycopg and having problems.
Several users will be selecting records from
a table using the same select statement and I don't
want users to select the same record at the same time.
example two users run statement concurrently
-----------------------------------------
(user 1)
begin;
select account from customer where customer is not null and chkout
is null order by account for update limit 10;
(10 rows returned)
1234
2341
3412
4123
.....
update 1234 set chkout = 'x'
end;
-----------------------------------------
(user 2)
begin;
select account from customer where customer is not null and chkout
is null order by account for update limit 10;
(since using the select for update, user 1 has a row lock
which will make user 2's select for update statement wait
until user 1 commits. Once user 1 commits, user 2's statement
re-evals it's query on the row that was locked and continues )
(9 rows returned)
2341
3412
4123
....
update 2341 set chkout = 'x'
end;
-----------------------------------------
When I try it with psycopg I get....
"ERROR: Can't serialize access due to concurrent update"
I must be missing something or maybe there's a better
way to get what I want done?
Any help would be great.
Ken
Ok, I guess I just don't know what the heck I'm
doing, but I got it working how I want by setting....
-----------------------------------------------------
dbfnt = psycopg.connect('dbname=','user=',serialize=0)
cur2 = dbfnt.cursor()
cur2.autocommit(1)
-----------------------------------------------------
Any input, or should I just move along?
|