Package org.jooq

Interface InsertReturningStep<R extends Record>

  • All Superinterfaces:
    Attachable, java.lang.AutoCloseable, java.util.concurrent.Flow.Publisher<java.lang.Integer>, Insert<R>, InsertFinalStep<R>, org.reactivestreams.Publisher<java.lang.Integer>, Query, QueryPart, RowCountQuery, java.io.Serializable, Statement
    All Known Subinterfaces:
    InsertOnConflictConditionStep<R>, InsertOnConflictWhereStep<R>, InsertOnDuplicateSetMoreStep<R>, InsertOnDuplicateStep<R>, InsertSetMoreStep<R>, InsertValuesStep1<R,​T1>, InsertValuesStep10<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10>, InsertValuesStep11<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11>, InsertValuesStep12<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12>, InsertValuesStep13<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13>, InsertValuesStep14<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14>, InsertValuesStep15<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15>, InsertValuesStep16<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16>, InsertValuesStep17<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17>, InsertValuesStep18<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17,​T18>, InsertValuesStep19<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17,​T18,​T19>, InsertValuesStep2<R,​T1,​T2>, InsertValuesStep20<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17,​T18,​T19,​T20>, InsertValuesStep21<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17,​T18,​T19,​T20,​T21>, InsertValuesStep22<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9,​T10,​T11,​T12,​T13,​T14,​T15,​T16,​T17,​T18,​T19,​T20,​T21,​T22>, InsertValuesStep3<R,​T1,​T2,​T3>, InsertValuesStep4<R,​T1,​T2,​T3,​T4>, InsertValuesStep5<R,​T1,​T2,​T3,​T4,​T5>, InsertValuesStep6<R,​T1,​T2,​T3,​T4,​T5,​T6>, InsertValuesStep7<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7>, InsertValuesStep8<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8>, InsertValuesStep9<R,​T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8,​T9>, InsertValuesStepN<R>

    public interface InsertReturningStep<R extends Record>
    extends InsertFinalStep<R>
    This type is used for the Insert's DSL API.

    Example:

     DSLContext create = DSL.using(configuration);
    
     TableRecord<?> record =
     create.insertInto(table, field1, field2)
           .values(value1, value2)
           .returning(field1)
           .fetchOne();
     

    This implemented differently for every dialect:

    • Firebird and Postgres have native support for INSERT .. RETURNING clauses
    • DB2 allows to execute SELECT .. FROM FINAL TABLE (INSERT ...)
    • HSQLDB, and Oracle JDBC drivers allow for retrieving any table column as "generated key" in one statement
    • Derby, H2, Ingres, MySQL, SQL Server only allow for retrieving IDENTITY column values as "generated key". If other fields are requested, a second statement is issued. Client code must assure transactional integrity between the two statements.
    • Sybase and SQLite allow for retrieving IDENTITY values as @@identity or last_inserted_rowid() values. Those values are fetched in a separate SELECT statement. If other fields are requested, a second statement is issued. Client code must assure transactional integrity between the two statements.

    Referencing XYZ*Step types directly from client code

    It is usually not recommended to reference any XYZ*Step types directly from client code, or assign them to local variables. When writing dynamic SQL, creating a statement's components dynamically, and passing them to the DSL API statically is usually a better choice. See the manual's section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql.

    Drawbacks of referencing the XYZ*Step types directly:

    • They're operating on mutable implementations (as of jOOQ 3.x)
    • They're less composable and not easy to get right when dynamic SQL gets complex
    • They're less readable
    • They might have binary incompatible changes between minor releases
    Author:
    Lukas Eder