I am executing a prepared batch insert into a Postgres table using pg-jdbc/JDBI in order to obtain a list of generated id values using an explicit RETURNING clause:
PreparedBatch b = getHandle().prepareBatch("INSERT INTO death_star(id,exhaust_port) VALUES ( :id, :exhaust_port) RETURNING id;");
for (RebelPilot p : rebelPilots) {
b.add().bind("id",p.getId()).bind("exhaust_port",p.getProtonTorpedo());
}
ResultSetMapper<Long> mapper = new IdMapper()
GeneratedKeys<Long> gk = b.executeAndGenerateKeys(mapper);
return gk.list()
When the statement is prepared, pg-jdbc will mindlessly append an extra RETURNING *
after the existing RETURNING
clause resulting in the following malformed abomination:
INSERT INTO death_star(id,exhaust_port) VALUES ( ?, ?) RETURNING id RETURNING *;
If I remove the explicit RETURNING clause, the statement works fine; however, it causes ALL fields from the target table to be returned, which is highly undesirable in many situations where large amounts of data have been inserted.
Is there any method to stop the pg-jdbc from engaging in this behavior?
Test Dependencies:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1207.jre7</version>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
<version>2.71</version>
</dependency>