pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paesold <mpaesold@gmx.at>
To: Ken Johanson <pg-user@kensystem.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Synthesize support for Statement.getGeneratedKeys()?
Date: Thu, 14 Dec 2006 08:50:08 +0100
Message-ID: <45810230.80803@gmx.at> (raw)
In-Reply-To: <4580E681.3080106@kensystem.com>
References: <4580E681.3080106@kensystem.com>

Ken Johanson wrote:
> Hello,
> 
> I've just come to realize that Statement.getGeneratedKeys() is not 
> supported in the current PG and/or JDBC driver. Does someone know if 
> this is a limitation of PG, or its protocol, or just not yet implemented 
> in the JDBC driver? I'm just wondering where, if at all (if I have 
> enough brain cells that is :), I could try to offer a patch or ideas..

It would be possible to implement that using the RETURNING clause 
supported in recent versions of the server.

See here:
http://archives.postgresql.org/pgsql-jdbc/2006-10/msg00035.php
http://archives.postgresql.org/pgsql-jdbc/2006-10/msg00037.php

Unfortunately, all my available spare time went into implementing 
support for standards_conforming_strings in the 8.2 release cycle.

> Then question 2; I did see a discussion where it was suggested that we 
> could get roughly the same effect by issuing a
> SELECT currval('<sequence-name>'); after the DML...
> http://archives.postgresql.org/pgsql-jdbc/2005-10/msg00035.php
> Would it then be feasible internal to the JDBC driver to (create an 
> option that would enable) always implicitly append that query to the 
> (String)sql arg of Statment.executeUpdate(String sql, String[] 
> columnNames)? I mean, just internally attempt to create the same 
> behavior as what this method should be doing?

As was discussed before, a solution just for sequences is not general 
enough, therefore the RETURNING thing.

> Question 3 is, it seems like option two would only return the last 
> created key, not set of keys, in the case where multiple rows were 
> inserted.. is this accurate?

Seems correct. And that's one of the objections to the idea.

> Unfortunately if I cant find a way to make my target-app work with PG 
> (without adding PG-specific modifications for getting keys), I'm 
> probably not going to be able to make the switch to PG unfortunately - 
> the code I'm working with makes really, really extensive use of 
> retrieved keys..

Could you comment on my mail above (the second one) -- what API-methods 
does your software use, actually?

Best Regards
Michael Paesold




view thread (50+ messages)  latest in thread

Message-ID: <45810230.80803@gmx.at>
Permalink:  ../45810230.80803@gmx.at/
Also on:    postgresql.org/message-id/45810230.80803@gmx.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: mpaesold@gmx.at, pg-user@kensystem.com
  Subject: Re: Synthesize support for Statement.getGeneratedKeys()?
  In-Reply-To: <45810230.80803@gmx.at>
  References: <4580E681.3080106@kensystem.com> <45810230.80803@gmx.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox