X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8A14052BBF for ; Wed, 27 Jul 2005 10:15:08 -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 49203-03 for ; Wed, 27 Jul 2005 13:14:56 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 7332952BC5 for ; Wed, 27 Jul 2005 10:14:53 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DxlkP-0006GX-AB; Thu, 28 Jul 2005 01:14:57 +1200 Message-ID: <42E788D0.5050902@opencloud.com> Date: Thu, 28 Jul 2005 01:14:56 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Peter.Zoche@materna.de Cc: pgsql-jdbc@postgresql.org Subject: Re: INSERT and get ID References: <3617A3C21370D045B75C0A40A7A6530D0B37E199@ntexc2buc.do-office.buc.materna.com> In-Reply-To: <3617A3C21370D045B75C0A40A7A6530D0B37E199@ntexc2buc.do-office.buc.materna.com> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.009 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/355 X-Sequence-Number: 13503 Peter.Zoche@materna.de wrote: > String insert = "INSERT INTO foo (id, val) > VALUES( nextval('myseq'), 5 )"; > int count = statement.executeUpdate( insert ); > > I only get the row count of inserted rows. Do I have to query the > database again to get the id? Currently, yes. You can usually do some trickery with currval() to run both an INSERT and a SELECT in the same statement and avoid an extra round-trip. > Or is there another way? I have tried > statement.executeUpdate( insert, Statement.RETURN_GENERATED_KEYS); > but I get an PSQLException saying that the feature of auto-generated keys > is not supported. Right, this really needs server-side support before we can implement it (INSERT ... RETURNING ... or similar) -O