X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 88948D1C946 for ; Fri, 1 Aug 2003 01:22:41 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 02636-01 for ; Thu, 31 Jul 2003 22:21:36 -0300 (ADT) Received: from mail.seaworthysystems.com (216-238-112-88.dsl.ct.thebiz.net [216.238.112.88]) by svr1.postgresql.org (Postfix) with ESMTP id 86D48D1C92C for ; Thu, 31 Jul 2003 22:22:39 -0300 (ADT) Received: from seaworthysystems.com (localhost.localdomain [127.0.0.1]) by mail.seaworthysystems.com (Postfix) with SMTP id 39FCB1B692; Thu, 31 Jul 2003 21:28:18 -0400 (EDT) Received: from 66.212.203.144 (SquirrelMail authenticated user btober) by $HOSTNAME with HTTP; Thu, 31 Jul 2003 21:28:18 -0400 (EDT) Message-ID: <65027.66.212.203.144.1059701298.squirrel@$HOSTNAME> Date: Thu, 31 Jul 2003 21:28:18 -0400 (EDT) Subject: Re: Does a the block of code within a stored procedure constitute a transaction? From: To: In-Reply-To: <1059698237.33557.8.camel@jester> References: <64821.216.238.112.88.1059509762.squirrel@$HOSTNAME> <1059698237.33557.8.camel@jester> X-Priority: 3 Importance: Normal Cc: X-Mailer: SquirrelMail (version 1.2.9) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/1 X-Sequence-Number: 14617 >> What I need to know is whether or not this is multi-user safe, i.e., >> will the block of code in the procedure execute as a transaction so >> that if more than one clerk creates an expense report for the same >> employee simultaneously is it possible or impossible that value of >> the >> employee.expense_report_seq gets updated by the second clerk between >> the SELECT and UPDATE statements invoked by the first clerk? >> >> And as a follow-up, should I add the FOR UPDATE clause to the SELECT >> statement? > > SELECT .. FOR UPDATE would be appropriate. > > However, you could also do an update + 1 first and the select second to > find what you changed the value to. Yes, and I like the fact that the UPDATE first approach eliminates a local variable declaration as well! ~Berend Tober