Skip to content

Return Generated ID in R2dbc Insert #34604

Open
@hantsy

Description

@hantsy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions