Top Description Methods
org.jooq

public Interface InsertOnDuplicateStep<R extends org.jooq.Record>

extends InsertReturningStep<R extends Record>
Known Direct Subinterfaces
org.jooq.InsertSetMoreStep, org.jooq.InsertValuesStep1, org.jooq.InsertValuesStep11, org.jooq.InsertValuesStep12, org.jooq.InsertValuesStep13, org.jooq.InsertValuesStep14, org.jooq.InsertValuesStep15, org.jooq.InsertValuesStep16, org.jooq.InsertValuesStep17, org.jooq.InsertValuesStep18, org.jooq.InsertValuesStep19, org.jooq.InsertValuesStep2, org.jooq.InsertValuesStep20, org.jooq.InsertValuesStep21, org.jooq.InsertValuesStep22, org.jooq.InsertValuesStep3, org.jooq.InsertValuesStep4, org.jooq.InsertValuesStep5, org.jooq.InsertValuesStep6, org.jooq.InsertValuesStep7, org.jooq.InsertValuesStep8, org.jooq.InsertValuesStep9, org.jooq.InsertValuesStepN, org.jooq.InsertValuesStep10
Static Imports
org.jooq.SQLDialect.CUBRID, .SQLDialect.DERBY, .SQLDialect.FIREBIRD, .SQLDialect.H2, .SQLDialect.HSQLDB, .SQLDialect.MARIADB, .SQLDialect.MYSQL, .SQLDialect.POSTGRES, .SQLDialect.SQLITE, .SQLDialect.YUGABYTEDB

Deprecated

as a consequence of InsertReturningStep being deprecated. See corresponding docs for further information.

This type is used for the Insert's DSL API.

Example:


DSLContext create = DSL.using(configuration);

create.insertInto(table, field1, field2)
      .values(value1, value2)
      .values(value3, value4)
      .onDuplicateKeyUpdate()
      .set(field1, value1)
      .set(field2, value2)
      .execute();

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:

Author
Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public @NotNull InsertOnConflictWhereIndexPredicateStep<R>
onConflict(Field<?>... keys)

Deprecated as a consequence of Field being deprecated.
Add an ON CONFLICT clause to this INSERT statement.
public @NotNull InsertOnConflictWhereIndexPredicateStep<R>
onConflict(Collection<? extends Field<?>> keys)

Add an ON CONFLICT clause to this INSERT statement.

public @NotNull InsertReturningStep<R>
onConflictDoNothing()

Deprecated as a consequence of InsertReturningStep being deprecated.
Add an ON CONFLICT DO NOTHING clause to this INSERT statement.
public @NotNull InsertOnConflictDoUpdateStep<R>
onConflictOnConstraint(Constraint constraint)

Deprecated as a consequence of Constraint being deprecated.
Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.
public @NotNull InsertOnConflictDoUpdateStep<R>
onConflictOnConstraint(Name constraint)

Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.

public @NotNull InsertOnConflictDoUpdateStep<R>
onConflictOnConstraint(UniqueKey<R> constraint)

Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.

public @NotNull InsertReturningStep<R>
onDuplicateKeyIgnore()

Deprecated as a consequence of InsertReturningStep being deprecated.
Add an ON DUPLICATE KEY IGNORE clause to this INSERT statement.
public @NotNull InsertOnDuplicateSetStep<R>
onDuplicateKeyUpdate()

Add an ON DUPLICATE KEY UPDATE clause to this INSERT statement.

Inherited from org.jooq.InsertReturningStep:
returningreturningreturningreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResultreturningResult

Method Detail

onConflictback to summary
public @NotNull InsertOnConflictWhereIndexPredicateStep<R> onConflict(Field<?>... keys)

Deprecated

as a consequence of Field being deprecated. See corresponding docs for further information.

Add an ON CONFLICT clause to this INSERT statement.

Only SQLDialect#POSTGRES and SQLDialect#SQLITE have native support for this clause. The other dialects can emulate it using MERGE, if table meta data is available.

Annotations
@NotNull
@CheckReturnValue
@Support
onConflictback to summary
public @NotNull InsertOnConflictWhereIndexPredicateStep<R> onConflict(Collection<? extends Field<?>> keys)

Add an ON CONFLICT clause to this INSERT statement.

Only SQLDialect#POSTGRES and SQLDialect#SQLITE have native support for this clause. The other dialects can emulate it using MERGE, if table meta data is available.

Annotations
@NotNull
@CheckReturnValue
@Support
onConflictDoNothingback to summary
public @NotNull InsertReturningStep<R> onConflictDoNothing()

Deprecated

as a consequence of InsertReturningStep being deprecated. See corresponding docs for further information.

Add an ON CONFLICT DO NOTHING clause to this INSERT statement.

Only SQLDialect#POSTGRES and SQLDialect#SQLITE have native support for this clause. The other dialects can emulate it using MERGE, if table meta data is available.

Annotations
@NotNull
@CheckReturnValue
@Support
onConflictOnConstraintback to summary
public @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Constraint constraint)

Deprecated

as a consequence of Constraint being deprecated. See corresponding docs for further information.

Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.

Annotations
@NotNull
@CheckReturnValue
@Support:CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB
onConflictOnConstraintback to summary
public @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Name constraint)

Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.

Annotations
@NotNull
@CheckReturnValue
@Support:CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, YUGABYTEDB
onConflictOnConstraintback to summary
public @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(UniqueKey<R> constraint)

Add a ON CONFLICT ON CONSTRAINT clause to this INSERT statement.

Annotations
@NotNull
@CheckReturnValue
@Support
onDuplicateKeyIgnoreback to summary
public @NotNull InsertReturningStep<R> onDuplicateKeyIgnore()

Deprecated

as a consequence of InsertReturningStep being deprecated. See corresponding docs for further information.

Add an ON DUPLICATE KEY IGNORE clause to this INSERT statement.

This will try to INSERT a record. If there is a primary key or unique key in this INSERT statement's affected table that matches the value being inserted, then the INSERT statement is ignored.

This clause is not actually supported in this form by any database, but can be emulated as such:

Dialect Emulation
SQLDialect#MYSQL and SQLDialect#MARIADB
INSERT IGNORE INTO …
SQLDialect#POSTGRES_9_5 and SQLDialect#SQLITE
INSERT INTO … ON CONFLICT DO NOTHING
SQLDialect#DB2
SQLDialect#HSQLDB
SQLDialect#ORACLE
SQLDialect#SQLSERVER
SQLDialect#SYBASE
MERGE INTO [dst]
USING ([values])
ON [dst.key] = [values.key]
WHEN NOT MATCHED THEN INSERT ..
All the others
INSERT INTO [dst] ( ... )
SELECT [values]
WHERE NOT EXISTS (
  SELECT 1
  FROM [dst]
  WHERE [dst.key] = [values.key]
)
Annotations
@NotNull
@CheckReturnValue
@Support
onDuplicateKeyUpdateback to summary
public @NotNull InsertOnDuplicateSetStep<R> onDuplicateKeyUpdate()

Add an ON DUPLICATE KEY UPDATE clause to this INSERT statement.

This will try to INSERT a record. If there is a primary key or unique key in this INSERT statement's affected table that matches the value being inserted, then the UPDATE clause is executed instead.

MySQL natively implements this type of clause. jOOQ can emulate this clause using a MERGE statement on some other databases. The conditions for a RDBMS to emulate this clause are:

H2 supports this clause in MySQL mode.

Annotations
@NotNull
@CheckReturnValue
@Support:CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB