Skip to content
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

Strongly-typed Record<R> RETURNING statement #16565

Open
jacekgajek opened this issue Apr 17, 2024 · 1 comment
Open

Strongly-typed Record<R> RETURNING statement #16565

jacekgajek opened this issue Apr 17, 2024 · 1 comment

Comments

@jacekgajek
Copy link

jacekgajek commented Apr 17, 2024

Use case

I'm using PostgreSQL Currently

        return dsl.insertInto(MYTABLE)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .returning(MYTABLE)
            .fetchOne()

Runs two statements: first insert, then select.

returningResult uses RETURNING, but there is no way to get a full record.

        return dsl.insertInto(MYTABLE)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .set(...)
            .returningResult(MYTABLE) // returns a generic Record with a field of type "MYTABLE"
            .fetchOne()

Possible solution

  1. a regular .returning() might also use RETURNING statement.
  2. add an asterisk overload for .returningResult()

Possible workarounds

  1. )Call .returning() inside a transaction.
            .returningResult(*MY_TABLE.fields())
            .fetchOne { it.into(MY_TABLE) }

jOOQ Version

Jooq 3.19.7

Database product and version

PostgreSQL 16.1

Java Version

openjdk 21.0.2

JDBC / R2DBC driver name and version (include name if unofficial driver)

org.postgresql:postgresql:42.7.3

@lukaseder
Copy link
Member

Runs two statements: first insert, then select.

I don't think jOOQ will do this with proper SQLDialect.POSTGRES configuration. Can you please show what you're doing with an MCVE? We have a template here: https://github.com/jOOQ/jOOQ-mcve

  1. a regular .returning() might also use RETURNING statement.

That's what should be done. The only difference between returning() and returningResult() is the shape of the resulting record(s). There's no difference in generated SQL

2. add an asterisk overload for .returningResult()

Why would you need it?

  1. )Call .returning() inside a transaction.

I'm not sure how a transaction would change anything, but I'm sure your MCVE will be able to help clarify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants