logo       

Re: concurrent select for updates / row locks - help!: msg#00114

Subject: Re: concurrent select for updates / row locks - help!
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?


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe