Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6ED3E9FB47B for ; Mon, 5 Mar 2007 18:28:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 92412-04 for ; Mon, 5 Mar 2007 18:28:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 496FF9FB451 for ; Mon, 5 Mar 2007 18:28:43 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 05 Mar 2007 14:28:36 -0800 Subject: Re: Fetching generated keys From: Mark Lewis To: Mike Clements Cc: "A.M." , PostgreSQL JDBC List In-Reply-To: <626C0646ACE5D544BC9675C1FB81846B3388D1@MAIL03.bedford.progress.com> References: <626C0646ACE5D544BC9675C1FB81846B3388D1@MAIL03.bedford.progress.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Mon, 05 Mar 2007 14:28:36 -0800 Message-Id: <1173133716.16656.1017.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27.rhel4.6) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200703/45 X-Sequence-Number: 16759 On Mon, 2007-03-05 at 17:19 -0500, Mike Clements wrote: ... > The FAQ you posted suggests that "currval" uses a level of isolation > that is more strict than the default "read committed". If so, setting > isolation level to serializable would be unnecessary. Is that true? Or > should I do it just to be safe? I'd hate to do it if unnecessary due to > the performance and locking implications. Yes, currval definitely returns the last value returned by the sequence in the current transaction. Anything done in other transactions is ignored. Just for kicks, I did a simple test with two psql sessions to demonstrate: psql1: BEGIN TRANSACTION; psql1: SELECT nextval('my_seq'); -- returns 4988 psql2: BEGIN TRANSACTION; psql2: SELECT nextval('my_seq'); -- returns 4989 psql1: SELECT currval('my_seq'); -- returns 4988 (also tested with psql2 committing the transaction before psql1 reads currval. Made no difference.) -- Mark Lewis