public interface InsertOnDuplicateStep<R extends Record> extends InsertReturningStep<R>
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();
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:
Modifier and Type | Method and Description |
---|---|
InsertOnConflictDoUpdateStep<R> |
onConflict(Collection<? extends Field<?>> keys)
Add an
ON CONFLICT clause to this insert query. |
InsertOnConflictDoUpdateStep<R> |
onConflict(Field<?>... keys)
Add an
ON CONFLICT clause to this insert query. |
InsertReturningStep<R> |
onConflictDoNothing()
Add an
ON CONFLICT DO NOTHING clause to this insert query. |
InsertOnConflictDoUpdateStep<R> |
onConflictOnConstraint(Constraint constraint)
Add a
ON CONFLICT ON CONSTRAINT clause to this query. |
InsertOnConflictDoUpdateStep<R> |
onConflictOnConstraint(Name constraint)
Add a
ON CONFLICT ON CONSTRAINT clause to this query. |
InsertOnConflictDoUpdateStep<R> |
onConflictOnConstraint(UniqueKey<R> constraint)
Add a
ON CONFLICT ON CONSTRAINT clause to this query. |
InsertReturningStep<R> |
onDuplicateKeyIgnore()
Add an
ON DUPLICATE KEY IGNORE clause to this insert query. |
InsertOnDuplicateSetStep<R> |
onDuplicateKeyUpdate()
Add an
ON DUPLICATE KEY UPDATE clause to this insert query. |
returning, returning, returning, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult, returningResult
bind, bind, cancel, close, execute, executeAsync, executeAsync, getBindValues, getParam, getParams, getSQL, getSQL, getSQL, isExecutable, keepStatement, queryTimeout
attach, configuration, detach
@Support(value={AURORA_POSTGRES,CUBRID,DB2,FIREBIRD_3_0,HSQLDB,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Constraint constraint)
ON CONFLICT ON CONSTRAINT
clause to this query.@Support(value={AURORA_POSTGRES,CUBRID,DB2,FIREBIRD_3_0,HSQLDB,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Name constraint)
ON CONFLICT ON CONSTRAINT
clause to this query.@Support InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(UniqueKey<R> constraint)
ON CONFLICT ON CONSTRAINT
clause to this query.@Support InsertOnConflictDoUpdateStep<R> onConflict(Field<?>... keys)
ON CONFLICT
clause to this insert query.
Only SQLDialect.POSTGRES
has native support for this clause. The
other dialects can emulate it using MERGE
, if table meta
data is available.
@Support InsertOnConflictDoUpdateStep<R> onConflict(Collection<? extends Field<?>> keys)
ON CONFLICT
clause to this insert query.
Only SQLDialect.POSTGRES
has native support for this clause. The
other dialects can emulate it using MERGE
, if table meta
data is available.
@Support InsertReturningStep<R> onConflictDoNothing()
ON CONFLICT DO NOTHING
clause to this insert query.
Only SQLDialect.POSTGRES
has native support for this clause. The
other dialects can emulate it using MERGE
, if table meta
data is available.
@Support(value={AURORA_MYSQL,AURORA_POSTGRES,CUBRID,DB2,H2,HSQLDB,INFORMIX,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE}) InsertOnDuplicateSetStep<R> onDuplicateKeyUpdate()
ON DUPLICATE KEY UPDATE
clause to this insert query.
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 and CUBRID 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:
INSERT
statement's table is a
Table
with a Table.getPrimaryKey()
MERGE
clause (see
DSLContext.mergeInto(Table)
).H2 supports this clause in MySQL mode.
@Support InsertReturningStep<R> onDuplicateKeyIgnore()
ON DUPLICATE KEY IGNORE
clause to this insert query.
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 |
|
SQLDialect.POSTGRES_9_5 |
|
SQLDialect.CUBRID |
|
SQLDialect.DB2 SQLDialect.HSQLDB SQLDialect.ORACLE SQLDialect.SQLSERVER SQLDialect.SYBASE |
|
All the others |
|
Copyright © 2019. All rights reserved.