Skip to content

Return Generated ID in R2dbc Insert #34604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hantsy opened this issue Mar 15, 2025 · 0 comments
Open

Return Generated ID in R2dbc Insert #34604

hantsy opened this issue Mar 15, 2025 · 0 comments
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@hantsy
Copy link
Contributor

hantsy commented Mar 15, 2025

When using Postgres, it is easy to add RETURNING id to attach the generated ID in the FetchSpec and extract it.

But when using H2 and Spring R2dbc, there is no built-in RETURNING support as Postgres.

The Jdbc also includes PrepareStatement.getGeneratedKeys() to fetch the generated key values. Spring Jdbc also include simple GeneratedKeyHolder to fetch the generated ID in the insert clause.

Spring Data R2dbc issues also mentioned it has resolved this issue, spring-projects/spring-data-r2dbc#14.

But the raw R2dbc API includes a Statement.returnGeneratedValues, but it is not adopted in the Spring R2dbc.

I wish there is a general solution for all database. When inserting a record, no need to add database specific RETURNING clause, provide a Spring Jdbc similar KeyHolder to store the generated keys in the query execution, and easily extract the key from the FetchSpec.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 15, 2025
@jhoeller jhoeller added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants