Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EECC69FB4D2 for ; Sun, 21 Jan 2007 15:07:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 61841-02 for ; Sun, 21 Jan 2007 15:06:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from www01.kensystem.com (www01.kensystem.com [72.19.170.120]) by postgresql.org (Postfix) with ESMTP id 080E69FA66C for ; Sun, 21 Jan 2007 15:06:56 -0400 (AST) Received: from 192.168.0.3 by www01.kensystem.com (SMTPD); id s20070121190651.8555; Sun, 21 Jan 2007 19:06:51 Message-ID: <45B3B9CB.3070308@kensystem.com> Date: Sun, 21 Jan 2007 12:06:51 -0700 From: Ken Johanson User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Dave Cramer CC: Michael Paesold , pgsql-jdbc@postgresql.org Subject: Re: Synthesize support for Statement.getGeneratedKeys()? References: <4580E681.3080106@kensystem.com> <45810230.80803@gmx.at> <45B1AC19.3090300@kensystem.com> <45B1F839.3060402@gmx.at> <45B254D7.4080304@kensystem.com> <55027648-0777-4BE4-8581-933E86180539@fastcrypt.com> In-Reply-To: <55027648-0777-4BE4-8581-933E86180539@fastcrypt.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/134 X-Sequence-Number: 16499 Dave Cramer wrote: >> >> 3) Is there a) an efficient RETURNING clause to pre-populate the >> generated-keys result set, or b) should I synthesize it. > > I take it from this that you are intending on returning all generated > columns?, just generated columns that have keys ? >> Yes, ideally. I'd prefer not to try and synthesize the values from only a single (last or first row's) key, since sequences can have increment values other than one, and because OIDs are not predictable (are they?). Other server generated key types also seem to make the synthetic idea unfeasible. >> 4) If 3b is required, then besides incrementing (by one) sequences, >> any suggestions on how to correctly synthesize other increment values? >> Other key types (OIDs, etc?) > > Are you suggesting here that you are planning on incrementing the > sequences by 1 ? Why not just let the insert occur and get the currval > of the sequence ? I'm thinking what you're thinking; get the current value; however the increment I mention is just in case I cant get more than one curval... I don't know, can I get 3 values from RETURN if I insert three VALUEs in one query?? >> >> 5) To be absolutely sure, inserting multiple values then getting the >> sequence back (RETURNING) will happen atomically in the server, correct? >> (to avoid getting another transaction's keys). > You don't want to return the sequence, as it can be changed by another > transaction, you want to return the value in the row that was inserted. >> Agreed.