Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 45E5D2E00A7 for ; Wed, 20 Feb 2008 10:03:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 67547-02-4 for ; Wed, 20 Feb 2008 10:03:32 -0400 (AST) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by postgresql.org (Postfix) with ESMTP id 7F3952E0067 for ; Wed, 20 Feb 2008 10:03:16 -0400 (AST) Received: by fg-out-1718.google.com with SMTP id 22so1979227fge.23 for ; Wed, 20 Feb 2008 06:03:14 -0800 (PST) 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:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=yPDtTj4s1Wq/NSsrX0ev11qZjAsysKYop/xBl78r2Bo=; b=uRU2jSDjt5KFK73oUHHByQQAsK4JYi5gIRyFfWhyIBl6Q6G6N2Bv20FT4eu0g4Lt2HuKqQlhtESjeA4ENNDtDT32bpECcXt2CdAyU/SQoxrsGwegvaUsjShfrNDJNFBehx4Iz1etu9gXQGSmNzL+aBdyybQ2PLOi8YFCVl1T//4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SL9XjKGprJUWAFgVaOSMS0jJTrg85D4uQPPC5u2KpLb53Umq4xKdTMCOXd0PY4+/qh5BArDdiW7OkxLOsFppLBUkS9Qb7dZC7ZH6Y26v1qBJRMSnwBryz1HHu3YA7sjXH7ScrBzKxPCQxIub5IL1RCi05lBGfJW3Vek8+TQSAf0= Received: by 10.82.166.9 with SMTP id o9mr14676822bue.34.1203516194636; Wed, 20 Feb 2008 06:03:14 -0800 (PST) Received: by 10.82.180.9 with HTTP; Wed, 20 Feb 2008 06:03:14 -0800 (PST) Message-ID: <8efd35820802200603p1d27c66dk1105608ac1495f5@mail.gmail.com> Date: Wed, 20 Feb 2008 09:03:14 -0500 From: "Paul Tomblin" To: pgsql-jdbc@postgresql.org Subject: Re: Retrieving last InsertedID : INSERT... RETURNING safe ? In-Reply-To: <47BC300E.1030507@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <38245.1203500677@motionsponsor.com> <47BC0AF6.2060500@enterprisedb.com> <87prurrh87.fsf@mnc.ch> <55C92F71-0317-4E91-A092-C22A7A2F1FD8@fastcrypt.com> <47BC1AC4.5010809@gmail.com> <9096E930-A528-4AF7-92B9-6EB1A5A52F84@fastcrypt.com> <47BC2798.9010300@enterprisedb.com> <8efd35820802200536n22c75f92u97474ab4d3a9cdee@mail.gmail.com> <47BC300E.1030507@enterprisedb.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: 200802/170 X-Sequence-Number: 18377 On Feb 20, 2008 8:50 AM, Heikki Linnakangas wrote= : > Paul Tomblin wrote: > > On Feb 20, 2008 8:14 AM, Heikki Linnakangas w= rote: > >> Dave Cramer wrote: > >>> I was going to say there are absolutely no situations where this is n= ot > >>> true, however in your case autocommit or not it doesn't matter. > >>> You have a single connection for the entire application and asynchron= ous > >>> events using that connection. Autocommit or not it will not work with > >>> currval. > >>> > >>> In your case you must use nextval before doing the insert. > >> Now you lost me. By asynchronous events, do you mean NOTIFY/LISTEN? Wh= at > >> exactly is the scenario you're talking about? > > > > In my case, we're talking about a system that has dozens of Java > > processes, many of which access the database. Because the system used > > to have autocommit on, one process could do the "insert nextval" and > > commit, and then another process could do an "insert nextval" and > > commit, and then the first process would do the "select currval" and > > would probably get the wrong value. > > From Dave's comment, I gather that those processes return the > connection to the pool and grab a new one between the "insert nextval" > and "select currval" steps? Yeah, I can see the problem in that case. No, there is no connection pooling yet. I'm working on that for the release after this one. =10Like I said, I was operating under the assumption that nextval/currval was bound to the transaction, not to the connection. I guess I was wrong. Be that as it may, I still don't see what you gain by doing insert ... (nextval('idseq'),... select currval('idseq'); when you could do select nextval('idseq'); insert ...(?,... --=20 For my assured failures and derelictions I ask pardon beforehand of my betters and my equals in my Calling here assembled, praying that in the hour of my temptations, weakness and weariness, the memory of this my Obligation and of the company before whom it was entered into, may return to me to aid, comfort and restrain.