Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id DF6E66346CA for ; Sat, 25 Apr 2009 10:22:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 89769-10 for ; Sat, 25 Apr 2009 10:22:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from MAIL91.interprise.dk (mail.interprise.dk [77.66.16.98]) by mail.postgresql.org (Postfix) with ESMTP id DF8CD6345F3 for ; Sat, 25 Apr 2009 10:22:01 -0300 (ADT) Received: from itcmail01.interprise.dk (172.22.110.33) by MAIL91.interprise.dk (172.22.200.10) with Microsoft SMTP Server (TLS) id 8.1.358.0; Sat, 25 Apr 2009 15:21:10 +0200 Received: from [192.168.1.7] (62.107.31.226) by SMTP.Trifork.com (172.22.110.33) with Microsoft SMTP Server (TLS) id 8.1.336.0; Sat, 25 Apr 2009 15:21:26 +0200 Message-ID: <49F30E48.4090207@trifork.com> Date: Sat, 25 Apr 2009 15:21:12 +0200 From: Jeppe Sommer User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Kris Jurka CC: "pgsql-jdbc@postgresql.org" Subject: Re: Here's a fix to AbstractJdbc3Statement.getGeneratedKeys References: <49F175A6.9080401@trifork.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/91 X-Sequence-Number: 19538 Kris Jurka skrev: > On Fri, 24 Apr 2009, Jeppe Sommer wrote: > > >> Porting a project from MySQL to PostgreSQL, I discovered that the jdbc3 >> facility of returning the generated keys from an insert statement does not >> work. On a fresh cvs checkout, there is partial support, however, all fields >> are returned, not only the field that are autogenerated. >> >> > > The problem is knowing what fields are autogenerated. A field that simply > has a default value may in fact be autogenerated. Also, what about a > before trigger which sets that value, that's also autogenerated. > > So what you are saying is that ResultSetMetaData.isAutoIncrement will only return true for a subset of the fields that are actually autogenerated? But perhaps it could serve as a starting point.. The jdbc apidoc is not very precise on what constitutes an autogenerated key, maybe autogenerated=autoincrement is even a valid interpretation? >> Here is a patch that fixes this. I hope someone will take a look, and >> consider whether it can be adopted into the project. Or improved. It works >> for me :-) >> >> The strategy of the patch is simply to inspect the metadata of the returned >> (initially full) resultset, and then strip out any fields that are not marked >> as autoincrement. >> >> > > I don't see how this helps. If it was able to avoid returning all fields > to the client, you could see how it would be a performance improvement, > but returning them all and then filtering is just adding more time isn't > it? > I'm not trying to improve performance, only to get the correct behaviour. I introduced the filtering because the application (actually the Spring framework) failed on receiving all fields when it was expecting only the generated field(s). > Kris Jurka > Jeppe