Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 967832E005C for ; Wed, 20 Feb 2008 07:25:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 03627-01-4 for ; Wed, 20 Feb 2008 07:25:44 -0400 (AST) Received: from relay1-v.mail.gandi.net (relay1-v.mail.gandi.net [217.70.178.75]) by postgresql.org (Postfix) with ESMTP id A86BE2E005E for ; Wed, 20 Feb 2008 07:25:49 -0400 (AST) Received: from localhost (front3-v.mgt.gandi.net [10.0.10.73]) by relay1-v.mail.gandi.net (Postfix) with ESMTP id B02AA362B5 for ; Wed, 20 Feb 2008 12:25:47 +0100 (CET) MIME-Version: 1.0 X-Mailer: Gandi Mail Message-ID: <39512.1203506747@motionsponsor.com> To: Reply-To: Content-Type: text/plain; charset="utf-8" X-Origin: 88.183.28.27 Date: Wed, 20 Feb 2008 12:25:47 +0100 Subject: Re: Retrieving last InsertedID : INSERT... RETURNING safe ? From: Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/155 X-Sequence-Number: 18362 Thanks Heikki ! That makes things clear to me now, i ll go on with the RETURNING method as = i have no restrictions in term of portability at all (lucky me :)) Thanks again Cheers Seb. Le mer , "Heikki Linnakangas" a =C3=A9crit: >spa >stor@motionsponsor.com wrote: >> Only one exception is regarding the best method to >retrieve the last inserted id (serial). There are many posts on this topic >but i couldn t find a definitive response.=20 >> I am using postgresql version 8.2.6 and jdbc 8.2_p505, >i ve been experiencing INSERT statement with RETURNING myID, using an >executeQuery it works great, i retrieve the proper value everytime at leas= t > from the few tests i have been doin locally. >> Is it THAT easy or could this method break somehow in a >live environement ? > > >It is that easy, and that is a good way to do it. > > > >Alternatively, if you need to support older PostgreSQL version for=20 > >example, you could use a "SELECT currval('sequence')" query after the=20 > >INSERT. > > > >Much of the of discussion you saw were probably about implementing the=20 > >JDBC getGeneratedKeys() function that some applications need for=20 > >portability reasons, or because of middleware that doesn't know how to=20 > >do INSERT RETURNING. PostgreSQL driver doesn't support that at the=20 > >moment, but as long as you don't need it, you'll be fine. > > > >--=20 > >Heikki Linnakangas > >EnterpriseDB http://www.enterprisedb.com > > >=20