X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A2A7C9F9B76 for ; Thu, 4 May 2006 15:50:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 04950-08 for ; Thu, 4 May 2006 15:50:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 1083C9FA7B6 for ; Thu, 4 May 2006 15:50:25 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id A87F8350E8; Thu, 4 May 2006 11:50:24 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A6A10350C9; Thu, 4 May 2006 11:50:24 -0700 (PDT) Date: Thu, 4 May 2006 11:50:24 -0700 (PDT) From: Stephan Szabo To: Ash Grove Cc: pgsql-sql@postgresql.org Subject: Re: is an explicit lock necessary? In-Reply-To: <20060504181056.14509.qmail@web52510.mail.yahoo.com> Message-ID: <20060504114708.I61331@megazone.bigpanda.com> References: <20060504181056.14509.qmail@web52510.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/53 X-Sequence-Number: 25084 On Thu, 4 May 2006, Ash Grove wrote: > Hi, > > Does beginning a transaction put locks on the tables > queried within the transaction? > > In the example below, is #2 necessary? My thought was > that I would need to use an explicit lock to make sure > that the sequence value I'm selecting in #4 is the > same one that is generated from #3. I'm worried about > another instance of the application doing an insert on > table1 between #3 and #4. If you have 1 session per instance and #3 and #4 are done after each other without any intervening commands, the behavior of nextval/currval should guarantee that (currval gives the value from this session's nextval, not any other).