X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C03B4D8833 for ; Fri, 7 Oct 2005 00:20:48 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45985-10 for ; Fri, 7 Oct 2005 03:20:39 +0000 (GMT) Received: from mail2.virtual-email.net (Mail2.virtual-email.net [213.228.203.184]) by svr1.postgresql.org (Postfix) with ESMTP id 32CFEDA4A8 for ; Fri, 7 Oct 2005 00:20:38 -0300 (ADT) Received: from [10.0.1.3] ([213.149.180.152]) by mail2.virtual-email.net over TLS secured channel with Microsoft SMTPSVC(6.0.3790.211); Fri, 7 Oct 2005 04:20:27 +0100 Message-ID: <4345E974.9020804@albourne.com> Date: Fri, 07 Oct 2005 06:20:20 +0300 From: Adriaan Joubert User-Agent: Debian Thunderbird 1.0.7 (X11/20051001) X-Accept-Language: en-gb MIME-Version: 1.0 To: Srinivasa_Tata@hud.gov Cc: pgsql-jdbc@postgresql.org Subject: Re: returning autogenerated keys References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------040702080202010102060201" X-OriginalArrivalTime: 07 Oct 2005 03:20:28.0188 (UTC) FILETIME=[10BE95C0:01C5CAEE] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200510/36 X-Sequence-Number: 13967 This is a multi-part message in MIME format. --------------040702080202010102060201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Yes, that is correct, postgres does not support returning auto-generated keys. You can get the auto generated keys by calling SELECT currval(''); on the same connection. We have remote users and latency is an issue. We combine the insert and the fetch of the remote keys, which does everything in a single trip to the database. sql = "INSERT ....; SELECT currval('')"; // Prepare the statement PreparedStatement st = connection.prepareStatement(sql); // Set the insert values ... // Insert the row st.execute(); int nInserted = st.getUpdateCount(); if (nInserted == 1 && st.getMoreResults()) { ResultSet rs = st.getResultSet(); if (rs.next()) result = rs.get(1); } That does everything in one go. Cheers, Adriaan Srinivasa_Tata@hud.gov wrote: > > > I am trying to use PostgreSQL and while trying to do a prototype, I am > getting an error. > > org.postgresql.util.PSQLException: Returning autogenerated keys is not > supported. > at > org.postgresql.jdbc3.AbstractJdbc3Statement.executeUpdate(AbstractJdbc3Statement.java:138) > > In the TODO list (INSERT section), it is mentioned that "This is > useful for returning the auto-generated key for an INSERT. One > complication is how to handle rules that run as part of the insert." > > Does it mean PostgreSQL does not support returning autogenerated keys? > I am using 803 version. > > Thanks In Advance > > Srinivas Tata_ > > _ > > --------------040702080202010102060201 Content-Type: text/x-vcard; charset=utf-8; name="a.joubert.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="a.joubert.vcf" begin:vcard fn:Adriaan Joubert n:Joubert;Adriaan org:Albourne Partners (Cyprus) Ltd adr:;;3 D. Vikella Street;Nicosia;;1061;Cyprus email;internet:a.joubert@albourne.com tel;work:+357 22 750652 tel;fax:+357 22 750654 x-mozilla-html:FALSE url:http://www.albourne.com version:2.1 end:vcard --------------040702080202010102060201--