Received: from earth.hub.org (earth.hub.org [64.49.215.11]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1G1sSE68712 for ; Fri, 15 Feb 2002 20:54:28 -0500 (EST) (envelope-from news@jupiter.hub.org) Received: (from news@localhost) by jupiter.hub.org (8.11.6/8.11.6) id g1G1pIT80569 for pgsql-sql@postgresql.org; Fri, 15 Feb 2002 19:51:18 -0600 (CST) (envelope-from news) From: "David Griffiths" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: SELECT... FOR UPDATE Date: Fri, 15 Feb 2002 17:49:49 -0800 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 50 Message-ID: References: <20020215155107.1e405665.postgres@vsservices.com> X-Complaints-To: news@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 To: pgsql-sql@postgresql.org X-Archive-Number: 200202/194 X-Sequence-Number: 6620 SELECT .... FOR UPDATE; locks all records returned from the SELECT. Anyone who tries to update any one of those records will block until you commit, rollback (or the connection is dropped and a rollback issued). It will ensure that no-one can modifiy the record(s). David "GB Clark" wrote in message news:20020215155107.1e405665.postgres@vsservices.com... > Hi, > > Can anyone give me a couple of examples or a explanation of select for update is supposed to work? > > I've looked in the manual and the locking stuff is confusing (or it could just be me not understanding..)) > and neither of my SQL books go into any type of detail on locking. > > What I want to do is select a record, do something and then update that record to reflect the outcome > of the processing with 0% chance of another process doing the same thing. Is this possiable? > > my idea: > > BEGIN > SELECT * FROM table1 WHERE record_id = '290202' FOR UPDATE > -- Do processing here > UPDATE table1 SET flag1 = '11' WHERE record_id = '290202' > COMMIT > > Just looking for more information.... > > Thanks, > > GB > > -- > GB Clark II | Roaming FreeBSD Admin > gclarkii@VSServices.COM | General Geek > CTHULU for President - Why choose the lesser of two evils? > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly