Received: from charon.simplot.com (jrsmailhub.simplot.com [12.18.144.212]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAGGu0m35073 for ; Fri, 16 Nov 2001 11:56:00 -0500 (EST) (envelope-from earlj@xanadu.simplot.com) Received: from xanadu.simplot.COM (151.113.0.132) by charon.simplot.com (MX V5.1-A AnGp) with SMTP; Fri, 16 Nov 2001 09:56:04 -0700 Received: from npa01zz001.simplot.com by xanadu.simplot.COM; (5.65v4.0/1.1.8.2/20Aug97-1116AM) id AA01546; Fri, 16 Nov 2001 09:56:03 -0700 Received: from earlj by npa01zz001.simplot.com with local (Exim 3.32 #1 (Debian)) id 164mHb-00031B-00; Fri, 16 Nov 2001 09:56:03 -0700 To: "Ross J. Reedstrom" CC: pgsql-sql@postgresql.org Subject: Re: INSERT question References: <1f5f2b44.0111130130.17e8e57a@posting.google.com> <3bf19679$0$189$e4fe514c@newszilla.xs4all.nl> <878zd7vpzn.fsf@npa01zz001.simplot.com> <87y9l7u3k5.fsf@npa01zz001.simplot.com> <20011115160902.E4187@rice.edu> From: Jason Earl Date: 16 Nov 2001 09:56:03 -0700 In-Reply-To: <20011115160902.E4187@rice.edu> Message-ID: <87lmh6u02k.fsf@npa01zz001.simplot.com> Lines: 32 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200111/246 X-Sequence-Number: 5628 Thanks for being patient with me. I must have fallen on my head yesterday or something. I *knew* currval and nextval were backend specific. I got confused because I am working on a middleware layer with a connection pool that grabs a connection and holds it until the transaction is finished. Each new transaction might grab a different backend, but you won't get a new backend until your transaction is finished. In other words, in my application the easiest way to insure that currval and nextval work like they should is to start a transaction (which grabs a backend connection). Apparently this has led to some very fuzzy thinking on my part. My apologies for sending contradictory and confusing posts to the list, and thanks for clearing that up. Jason "Ross J. Reedstrom" writes: > Let me say this again, since my previous post is probably unclear: > > The code below is safe, even without a transaction, _if it runs in one, > unshared connection to the DB_. So the danger is much less than you > might think. Adding the transaction is good (though nextval() _does not_ > rollback, BTW: you get holes in the sequence) because it protects your > data integrity (no orphan parent records if child fails for other reasons) > and lets any layers in between know that these go together, not because > it's needed to cover the multiuser case. > > Ross