From: | Frédéric Trégon <frederic(dot)tregon(at)codingame(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Cc: | developers <developers(at)codingame(dot)com> |
Subject: | RETURN_GENERATED_KEYS does not work when insert statement is using a "with" query. |
Date: | 2017-09-01 09:26:11 |
Message-ID: | CAPptqbrmbTbuKRCp0w0VxcLDWpegV5ZnecYer3gSzw2pSWodNA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Greetings,
I believe I found a defect in the latest postgresql driver (42.1.4) which
did not occur with the earlier version 9.3-1102-jdbc41.
For a PreparedStatement used for inserting with the option
RETURN_GENERATED_KEYS, if the sql contains a "with" query, then the
generated keys are not returned.
For example:
---
create table testjdbckey (
id SERIAL PRIMARY KEY,
mydate date
);
---
String sql = "WITH t AS (SELECT NOW() AS thedate) INSERT INTO
testjdbckey (mydate) VALUES ((SELECT thedate FROM t))";
Connection conn =...;
PreparedStatement ps = conn.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
while (rs.next()) {
// Will not enter the while loop with postgresql-42.1.4
System.out.println("Key: " + rs.getInt(1));
}
---
Of course if I remove the "with" and inline my subrequest it works. This
used to work perfectly with the 9.3-1102-jdbc41 driver.
What do you think?
Best Regards,
---
*Frédéric Trégon*
VP Engineering, CodinGame
+33 6 23 29 70 95
www.codingame.com
<http://plus.google.com/+Codingame> <http://twitter.com/codingame>
<http://www.facebook.com/CodinGame>
<https://www.youtube.com/channel/UCJ6woCHjGCBXqpf91SsAcoQ>
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2017-09-01 11:44:30 | Re: Statement-level rollback |
Previous Message | David G. Johnston | 2017-08-31 16:48:58 | Re: Statement is still active at the back-end even after closing |