Re: Synthesize support for Statement.getGeneratedKeys()? - Mailing list pgsql-jdbc

From Ken Johanson
Subject Re: Synthesize support for Statement.getGeneratedKeys()?
Date
Msg-id 45B1AFC2.5060900@kensystem.com
Whole thread Raw
In response to Re: Synthesize support for Statement.getGeneratedKeys()?  (Ken Johanson <pg-user@kensystem.com>)
List pgsql-jdbc
>
> 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?).
>
> 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?
>

Answering my own question here... sort of :)
http://www.postgresql.org/docs/current/static/sql-insert.html

In the case of inserting multiple values (say 3 rows), is there a clever
way to get the last 3 sequences via native SQL? Or would the JDBC code
need to synthesize them?: (very simplified)

...exec
rs.next();//single key returned
Object id = rs.getObject();
Object[] keys = new Object[insertedRowCount];
for (; keys.length; i++)
   keys[i] = increment(id);
myPGResultSet.populate(userDeclaredKeyNameOrIdx, keys);//hypothetical -
i didn't look at the API yet, sorry



pgsql-jdbc by date:

Previous
From: Ken Johanson
Date:
Subject: Re: Synthesize support for Statement.getGeneratedKeys()?
Next
From: Michael Paesold
Date:
Subject: Re: Synthesize support for Statement.getGeneratedKeys()?