Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3E12447680C for ; Wed, 13 Nov 2002 15:02:22 -0500 (EST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by postgresql.org (Postfix) with ESMTP id 16C5247648C for ; Wed, 13 Nov 2002 15:02:15 -0500 (EST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.6/8.12.6) with ESMTP id gADK1SMU015525; Wed, 13 Nov 2002 13:01:28 -0700 (MST) Date: Wed, 13 Nov 2002 13:03:05 -0700 (MST) From: "scott.marlowe" To: David Busby Cc: Subject: Re: Need to select and update with the same sql statement In-Reply-To: <026501c28b4a$fe1a1c40$4000000a@busbydev> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailBodyFilter: Message body has not been filtered X-MailScanner: Found to be clean X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/57 X-Sequence-Number: 1639 On Wed, 13 Nov 2002, David Busby wrote: > List, > I need to do a command like: > > select * from "table" where "id"=54; update "table" set "col"=value > where "id"=just selected id > > Is that possible? How would I work that into a StoredProcedure? I'm > getting a race condition where two+ clients are asking for data but getting > the same record, (each record is a datachunk for a distributed client). > This results in each client working on the same data, not good. Any ideas? > I'm posting to the php/sql list cause the clients ask for the datachunk via > SOAP request that is processed via PHP. Any assistance would be great It's time for transactions! You should be able to do this in a transaction: (pg_exec the SQL code here) begin; select * from table where "id"=54; (assign the id to a var $id here) update "table" set "col"=$value where "id"=$id; end; This should happen in such a way that other users can't see what's happening until it's done.