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 5801B9F9B76 for ; Thu, 4 May 2006 15:11:13 -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 98468-08 for ; Thu, 4 May 2006 15:11:00 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web52510.mail.yahoo.com (web52510.mail.yahoo.com [206.190.48.193]) by postgresql.org (Postfix) with SMTP id EF22C9F9C10 for ; Thu, 4 May 2006 15:10:59 -0300 (ADT) Received: (qmail 14511 invoked by uid 60001); 4 May 2006 18:10:56 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=4MRnUXaLijQOyFHJdknUu0O4yEv3eN/ulIIQIMWoQA+2ldhDhehShwZg2ZoE/tm8kwP2oB4Z790dF0SAXihkSzg6IaAFdyQZYWq7fjSXcCvuZCbeUlIIxMU9Bzmv8zDzqwj7LahVQpUV3nrRlVC7H4kHIv062tCFtB23LmBe7Lc= ; Message-ID: <20060504181056.14509.qmail@web52510.mail.yahoo.com> Received: from [144.171.145.25] by web52510.mail.yahoo.com via HTTP; Thu, 04 May 2006 11:10:56 PDT Date: Thu, 4 May 2006 11:10:56 -0700 (PDT) From: Ash Grove Subject: is an explicit lock necessary? To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/51 X-Sequence-Number: 25082 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. 1) From my app, I turn off autocommit. 2) I lock table1 in access exclusive mode 3) I do an insert into table1 which generates a primary key via nextval on sequence1 4) I grab grab the primary key value via currval on sequence1 5) I do an insert on table2 which includes table1's primary key so I can join the records later. 6) I manually commit Thanks! Ash __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com