Skip site navigation (1) Skip section navigation (2)

Re: Retrieving last InsertedID : INSERT... RETURNING safe ?

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Paul Tomblin" <ptomblin(at)gmail(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Retrieving last InsertedID : INSERT... RETURNING safe ?
Date: 2008-02-20 14:26:05
Message-ID: 47BC387D.60008@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Paul Tomblin wrote:
> Be that as it may, I still don't see what you gain by doing
>   insert ... (nextval('idseq'),...
>   select currval('idseq');
> when you could do
>   select nextval('idseq');
>   insert ...(?,...

Oh, sure, there's not gain either way. Select nextval + insert works 
just as well.

Theoretically, you could "pipeline" the "INSERT nextval" + "SELECT 
currval" method, by sending both commands at once and only then block 
and wait for response, saving one round-trip to the server. You could do 
that with a batch statement, I think, or by single executeQuery("INSERT 
... ; SELECT currval(...)"). But if you don't do that, there's no 
difference.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

In response to

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2008-02-20 17:18:43
Subject: Re: extra rowcopy in ResultSet allways needed ?.
Previous:From: Paul TomblinDate: 2008-02-20 14:03:14
Subject: Re: Retrieving last InsertedID : INSERT... RETURNING safe ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group