question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return all generated keys for inserts

See original GitHub issue

If multiple values are inserted with Statement.RETURN_GENERATED_KEYS set, driver returns only the last generated key/identity value on calling getGeneratedKeys. But according to JDBC spec,

The ResultSet object returned by getGeneratedKeys will contain a row for each value that a statement generated.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:14
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
peterbaecommented, Jul 7, 2020

This is a limitation from SQL Server’s end and there’s not much the driver can do. After speaking with the SQL Server team, changing the server response to return all generated keys instead of the last one (similar to OracleDB for example) would not be a trivial task, and the change likely won’t be made as it will break a lot of existing design. However, we’re keeping this issue open for future references.

2reactions
lilgreenbirdcommented, Aug 12, 2022

@stolsvik please re-read comment above that this is a SQL Server limitation. This issue is left open for tracking purposes only the driver team is not going to be implementing any hacks to workaround. This is filed in our backlog we will look into supporting when SQL Server addresses the limitation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrieving auto-generated keys for an INSERT statement - IBM
To retrieve automatically generated keys that are generated by an INSERT statement, you need to perform these steps: Use one of the following...
Read more >
Returning the Generated Keys in JDBC - Baeldung
Learn how to return auto-generated keys with only the JDBC. ... String QUERY = "insert into persons (name) values (?)" ...
Read more >
JDBC How to get all generated keys from single insert with ...
For SQL Server 2008 and later, adding an OUTPUT clause to the INSERT statement seems to do the trick: try (Statement st =...
Read more >
Autogenerated keys
JDBC's auto-generated keys feature provides a way to retrieve values from columns that are part of an index or have a default value...
Read more >
How to get primary key value (auto-generated keys) from ...
If you insert records into a table which contains auto-incremented column, using a Statement or, PreparedStatement objects. You can retrieve ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found