Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id DDF189FB232 for ; Mon, 5 Mar 2007 17:09:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 71079-08 for ; Mon, 5 Mar 2007 17:08:54 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.174]) by postgresql.org (Postfix) with ESMTP id 627CA9FB26C for ; Mon, 5 Mar 2007 17:08:57 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so1257061ugf for ; Mon, 05 Mar 2007 13:08:56 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=suFIJlLQady8dBymOcW1PUSB6OYnz/aJt09KdLhi/XQls3zuMkLQzDqpvAeClwiVZvJ+I5pKrBLxS7DQ7rdXZMTMq7AyzSV2haiwP8ZNs7bJvQGcmunv9w0GOMGB4mrlCg1DFnrzkSIZ4lQ98pDzkikgn502yq1+mK+/n5CRdIA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=afNW2QEpi6Y1585eQKEw+UZO8LyJMw/hEfqXA0mBWTzw+JhO+5f+j5CNRjUnN+6jT1FLNEXxoVNc28as3sKAGAolpurOJ9PxGRzZQUw2vwPw6h5iQqPtXy3zSXOIdSqdsZ1jTaAx5iJ8+QQ2ZKZi+jcvQ8bqYMwXTkJY7pPN0l4= Received: by 10.67.29.12 with SMTP id g12mr11544341ugj.1173128935811; Mon, 05 Mar 2007 13:08:55 -0800 (PST) Received: from ?192.168.1.34? ( [81.107.202.67]) by mx.google.com with ESMTP id b36sm15487942ika.2007.03.05.13.08.52; Mon, 05 Mar 2007 13:08:54 -0800 (PST) Message-ID: <45EC86E2.8020506@enterprisedb.com> Date: Mon, 05 Mar 2007 21:08:50 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.8 (X11/20061116) MIME-Version: 1.0 To: Mike Clements CC: PostgreSQL JDBC List Subject: Re: Fetching generated keys References: <626C0646ACE5D544BC9675C1FB81846B3388B1@MAIL03.bedford.progress.com> In-Reply-To: <626C0646ACE5D544BC9675C1FB81846B3388B1@MAIL03.bedford.progress.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/40 X-Sequence-Number: 16754 Mike Clements wrote: > Up to now, we were selecting the current value of the sequence > immediately after the insert. I thought this was safe because > transactions should be isolated. But now I realize this could > potentially fail because the default transaction isolation is "read > committed". Thus if another connection inserts into the same table, > causing the sequence to increment, if it commits before we read the > sequence value, we might read the wrong value (the value as incremented > by the other transaction, not the value as it was for our own insert). You should use the lastval-function. It retrieves the last value returned in your connection. "SELECT lastval('sequence')" -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com