Module org.jooq
Package org.jooq

Interface InsertResultStep<R extends Record>

All Superinterfaces:
Attachable, AttachableQueryPart, AutoCloseable, Flow.Publisher<R>, Iterable<R>, Publisher<R>, org.reactivestreams.Publisher<R>, Query, QueryPart, ResultQuery<R>, Serializable, Statement

public interface InsertResultStep<R extends Record> extends ResultQuery<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:

  • 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, another statement is issued. Client code must assure transactional integrity between these 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