Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 436EA9FB3AE for ; Sat, 20 Jan 2007 13:43:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 53974-06 for ; Sat, 20 Jan 2007 13:43:55 -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 CE2E79FB3A3 for ; Sat, 20 Jan 2007 13:43:55 -0400 (AST) Received: from 192.168.0.3 by www01.kensystem.com (SMTPD); id s20070120174351.6954; Sat, 20 Jan 2007 17:43:51 Message-ID: <45B254D7.4080304@kensystem.com> Date: Sat, 20 Jan 2007 10:43:51 -0700 From: Ken Johanson User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Michael Paesold CC: 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> In-Reply-To: <45B1F839.3060402@gmx.at> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/130 X-Sequence-Number: 16495 >> If someone has pointers to where the augmentaion code should be placed >> (org.tgresql.jdbc3.Jdbc3ResultSetMetadata I presume), and also the >> protocol (separate query to the server?, or append RETURNING clause to >> the DML?). > > Right now, the server protocol does not have a separate facility for the > RETURNING functionality. Therefore you have to append a RETURNING clause > to the query string. > >> Also I cant remember - is it true that when inserting multuple VALUES, >> that only the first (or last) SEQUENCE can be retrived, or can I >> populate a resultset using the RETURNING data from by the server? > > I suppose it should work with multiple VALUES, but you can simple try. ;-) > For the PG & SQL masters out there, I am brain storming this... 1) It seems implicit that I will have to scan the input query for an existing RETURNING clause, and replace it if it exists; is there any pre-built query parsing helpers that would help with this? Or for efficiency I would need to do an indexOf that scans from the end of the CharSequence... thoughts? 2) Any queries where simply appending a RETURNING can somehow spoof functionality (UPDATEs, etc), or cause unintended results? Is it always permissible for RETURNING to be last? (i.e can it appear after other user clauses, LIMIT, etc) 3) Is there a) an efficient RETURNING clause to pre-populate the generated-keys result set, or b) should I synthesize it. 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?) 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). If someone wants to write up a spec on how this should work then I'll try to implement it in code. I can work without a spec but I'll make more incorrect assumptions (not being PG proficient yet). Thanks, Ken