Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AD1ED4767FB for ; Thu, 14 Nov 2002 08:35:25 -0500 (EST) Received: from wolff.to (unknown [66.93.197.35]) by postgresql.org (Postfix) with SMTP id 5C6D9476508 for ; Thu, 14 Nov 2002 08:35:23 -0500 (EST) Received: (qmail 20173 invoked by uid 500); 14 Nov 2002 13:45:14 -0000 Date: Thu, 14 Nov 2002 07:45:14 -0600 From: Bruno Wolff III To: "scott.marlowe" Cc: David Busby , pgsql-php@postgresql.org Subject: Re: Need to select and update with the same sql statement Message-ID: <20021114134514.GA20110@wolff.to> Mail-Followup-To: "scott.marlowe" , David Busby , pgsql-php@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/64 X-Sequence-Number: 1646 On Wed, Nov 13, 2002 at 15:26:42 -0700, "scott.marlowe" wrote: > > Oh, I just thought of the better way than locking the whole table is to > use a "select for update" on the row you want to lock. I think that'll do > what you want and without locking the whole table. Of course, 20 lines of > PHP code runs pretty fast, so unless you're handling lotsa traffic locking > the table probably works fine too. This came up in a discussion recently and it really isn't better. If you do this you have to worry about the select for update returning zero rows (even with the limit 1 clause) and retry the query if it does.