spring-projects / spring-projects/spring-framework

Return Generated ID in R2dbc Insert

Open
#34,604 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: data status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

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, https://github.com/spring-projects/spring-data-r2dbc/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the R2DBC Statement.returnGeneratedValues API and Spring R2DBC's insert and FetchSpec execution paths. The issue names no Spring Framework files or tests; done would require a decided, database-independent way to request, retain, and extract generated keys, including H2 and PostgreSQL behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.