[JDBC] RETURN_GENERATED_KEYS does not work when insert statement is using a"with" query.

Поиск
Список
Период
Сортировка
От Frédéric Trégon
Тема [JDBC] RETURN_GENERATED_KEYS does not work when insert statement is using a"with" query.
Дата
Msg-id CAPptqbrmbTbuKRCp0w0VxcLDWpegV5ZnecYer3gSzw2pSWodNA@mail.gmail.com
обсуждение исходный текст
Ответы Re: [JDBC] RETURN_GENERATED_KEYS does not work when insert statementis using a "with" query.  (Vladimir Sitnikov <sitnikov.vladimir@gmail.com>)
Re: RETURN_GENERATED_KEYS does not work when insert statementis using a "with" query.  (Vladimir Sitnikov <sitnikov.vladimir@gmail.com>)
Список 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

   


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [JDBC] Statement is still active at the back-end even after closing
Следующее
От: Vladimir Sitnikov
Дата:
Сообщение: Re: RETURN_GENERATED_KEYS does not work when insert statementis using a "with" query.