Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 4ABA42E0064 for ; Wed, 20 Feb 2008 09:51:20 -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 62829-09 for ; Wed, 20 Feb 2008 09:51:12 -0400 (AST) Received: from mail01.enterprisedb.com (mail01.enterprisedb.com [63.246.7.168]) by postgresql.org (Postfix) with ESMTP id 14A7F2E0060 for ; Wed, 20 Feb 2008 09:51:11 -0400 (AST) thread-index: Achzx7pZcV9zsKCfReyoFAgxidRZzg== Received: from [192.168.1.33] ([81.109.253.218]) by mail01.enterprisedb.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 20 Feb 2008 08:51:42 -0500 Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 Message-ID: <47BC300E.1030507@enterprisedb.com> Date: Wed, 20 Feb 2008 13:50:06 +0000 From: "Heikki Linnakangas" Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) MIME-Version: 1.0 To: "Paul Tomblin" Cc: Subject: Re: Retrieving last InsertedID : INSERT... RETURNING safe ? 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> In-Reply-To: <8efd35820802200536n22c75f92u97474ab4d3a9cdee@mail.gmail.com> Content-Type: text/plain; format=flowed; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 20 Feb 2008 13:51:42.0984 (UTC) FILETIME=[B99D5080:01C873C7] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/167 X-Sequence-Number: 18374 Paul Tomblin wrote: > On Feb 20, 2008 8:14 AM, Heikki Linnakangas wrote: >> Dave Cramer wrote: >>> I was going to say there are absolutely no situations where this is not >>> true, however in your case autocommit or not it doesn't matter. >>> You have a single connection for the entire application and asynchronous >>> 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? What >> 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. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com