Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id AAB379FB28E for ; Tue, 6 Mar 2007 17:05:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 30453-05 for ; Tue, 6 Mar 2007 17:05:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mx1.progress.com (mx1.progress.com [192.77.186.16]) by postgresql.org (Postfix) with ESMTP id 567929FB25E for ; Tue, 6 Mar 2007 17:05:51 -0400 (AST) Received: from mx1.progress.com (127.0.0.1) by mx1.progress.com (MlfMTA v3.2r1b3) id htnbqu0171sf for ; Tue, 6 Mar 2007 16:05:42 -0500 (envelope-from ) Received: from progress.com ([192.233.92.16]) by mx1.progress.com (SonicWALL 5.0.2.8415) with ESMTP; Tue, 06 Mar 2007 16:05:42 -0500 Received: from NTEXFE01.bedford.progress.com (ntexfe01 [172.16.2.61]) by progress.com (8.13.8/8.13.8) with ESMTP id l26L5gN5005119 for ; Tue, 6 Mar 2007 16:05:42 -0500 (EST) Received: from MAIL03.bedford.progress.com ([172.16.2.59]) by NTEXFE01.bedford.progress.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 6 Mar 2007 16:05:42 -0500 x-mimeole: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: Fetching generated keys Date: Tue, 6 Mar 2007 16:05:39 -0500 Message-ID: <626C0646ACE5D544BC9675C1FB81846B338938@MAIL03.bedford.progress.com> In-Reply-To: <626C0646ACE5D544BC9675C1FB81846B3388DC@MAIL03.bedford.progress.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [JDBC] Fetching generated keys Thread-Index: AcdfdaAMt0VbDaywQCmIlReIyOOQlgABZSeAAC3eYgA= From: "Mike Clements" To: "PostgreSQL JDBC List" X-OriginalArrivalTime: 06 Mar 2007 21:05:42.0536 (UTC) FILETIME=[33676080:01C76033] X-Mlf-Version: 5.0.2.8415 X-Mlf-UniqueId: o200703062105420043210 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/57 X-Sequence-Number: 16771 Hi everyone - one more question. I can prepare this "INSERT ... RETURNING" statement, but I can't run it or fetch the results from the JDBC driver. I figured it would have to work one of 2 ways: 1. call executeUpdate() and then getGeneratedKeys(). 2. call executeQuery() and use the result set. But both fail! If I call statement.executeUpdate(), it throws an exception saying it unexpectedly returned a result set. If I call statement.executeQuery(), it throws an exception saying the connection is already closed ?!?! What is the right way to get the results back from an insert using the "INSERT ... RETURNING" clause? Thanks -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Mike Clements Sent: Monday, March 05, 2007 6:10 PM To: Mark Lewis Cc: PostgreSQL JDBC List Subject: Re: [JDBC] Fetching generated keys Thanks everyone for the quick help and explanations. -----Original Message----- From: Mark Lewis [mailto:mark.lewis@mir3.com] Sent: Monday, March 05, 2007 5:29 PM To: Mike Clements Cc: A.M.; PostgreSQL JDBC List Subject: Re: [JDBC] Fetching generated keys On Mon, 2007-03-05 at 17:19 -0500, Mike Clements wrote: ... > The FAQ you posted suggests that "currval" uses a level of isolation=20 > that is more strict than the default "read committed". If so, setting=20 > 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=20 > 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 ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend