Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BA36A650172 for ; Fri, 1 Aug 2008 22:07:14 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 18416-07 for ; Fri, 1 Aug 2008 22:07:05 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.175]) by postgresql.org (Postfix) with ESMTP id AA74864FCF5 for ; Fri, 1 Aug 2008 22:07:10 -0300 (ADT) Received: by wf-out-1314.google.com with SMTP id 25so1101256wfc.28 for ; Fri, 01 Aug 2008 18:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=U54dQVvdFW03hHgxALbF7nqyG7xEF3rT83vRF2svmM0=; b=U0DycI6BZIhV6YQAgY8uPzxFc1BtM2uaegkSHTvnpEM9uIg84gfjEhXSKP4D2ipueI 5IzB50oPBdh9pV9JtLbgqrL8UVIq0MGRqPO0Phzn8gf0s/4rZef1g8SbaRhFkX7aEPYD jOLDAXkUmW86RdbGkAfM6qLH3GJrOPQlcTVBU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=tfGo2v/cw+bnLwPZeJ/8mhixG7MYj7BogrfdYooKiLTmj7k2jYPo/IX2Vw7bgA4Jop 9T5WFlH3ItaPxa48zagPO4Vh9lyy3d24LQRNmKHdkHjJeoM8VU8Zv7CNjNNMlAd50VgQ PUWFo32Woc/EiBqVX1A20MLi3ElauqzeWcka0= Received: by 10.142.132.2 with SMTP id f2mr3966687wfd.256.1217639229007; Fri, 01 Aug 2008 18:07:09 -0700 (PDT) Received: by 10.142.153.17 with HTTP; Fri, 1 Aug 2008 18:07:08 -0700 (PDT) Message-ID: Date: Fri, 1 Aug 2008 19:07:08 -0600 From: "Scott Marlowe" To: "EXT-Rothermel, Peter M" Subject: Re: [SQL] Savepoints and SELECT FOR UPDATE in 8.2 Cc: pgsql-interfaces@postgresql.org, pgsql-general@postgresql.org, pgsql-sql@postgresql.org In-Reply-To: <8D9E4E8445BD14478121CC9B027B518AB57AA0@XCH-NW-11V2.nw.nos.boeing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8D9E4E8445BD14478121CC9B027B518AB57AA0@XCH-NW-11V2.nw.nos.boeing.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/47 X-Sequence-Number: 135877 On Fri, Aug 1, 2008 at 11:02 AM, EXT-Rothermel, Peter M wrote: > > I was thinking of something like this: > > connect to DB > > BEGIN > > SELECT * FROM table_foo where foo_state = 'queued' FOR UPDATE; > for each row > do [ > > SAVEPOINT s; > UPDATE foo_resource SET in_use = 1 WHERE ...; > > status = application_logic_code(foo_column1, foo_column2); > > IF status OK > THEN > ROLLBACK TO SAVEPOINT s; > ELSE > RELEASE SAVEPOINT s; > ENDIF > ] > > > COMMIT; > > I found a caution in the documentation that says that SELECT FOR UPDATE > and SAVEPOINTS is not implemented correctly in version 8.2: > > http://www.postgresql.org/docs/8.2/interactive/sql-select.html#SQL-FOR-U > PDATE-SHARE > > Any suggestions? Why not plain rollback?