- All Superinterfaces:
Attachable
,AttachableQueryPart
,DMLQuery<R>
,Flow.Publisher<Integer>
,Insert<R>
,InsertFinalStep<R>
,InsertReturningStep<R>
,Publisher<Integer>
,org.reactivestreams.Publisher<Integer>
,Query
,QueryPart
,RowCountQuery
,Serializable
,Statement
- All Known Subinterfaces:
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>
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:
- 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
-
Method Summary
Modifier and TypeMethodDescription@NotNull InsertOnConflictWhereIndexPredicateStep
<R> onConflict
(Collection<? extends Field<?>> keys) Add anON CONFLICT
clause to this INSERT statement.@NotNull InsertOnConflictWhereIndexPredicateStep
<R> onConflict
(Field<?>... keys) Add anON CONFLICT
clause to this INSERT statement.@NotNull InsertReturningStep
<R> Add anON CONFLICT DO NOTHING
clause to this INSERT statement.@NotNull InsertOnConflictDoUpdateStep
<R> onConflictOnConstraint
(Constraint constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement.@NotNull InsertOnConflictDoUpdateStep
<R> onConflictOnConstraint
(Name constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement.@NotNull InsertOnConflictDoUpdateStep
<R> onConflictOnConstraint
(UniqueKey<R> constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement.@NotNull InsertReturningStep
<R> Add anON DUPLICATE KEY IGNORE
clause to this INSERT statement.@NotNull InsertOnDuplicateSetStep
<R> Add anON DUPLICATE KEY UPDATE
clause to this INSERT statement.Methods inherited from interface org.jooq.Attachable
attach, configuration, detach
Methods inherited from interface org.jooq.AttachableQueryPart
getBindValues, getParam, getParams, getSQL, getSQL
Methods inherited from interface org.jooq.InsertReturningStep
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
Methods inherited from interface org.reactivestreams.Publisher
subscribe
Methods inherited from interface org.jooq.Query
bind, bind, cancel, execute, executeAsync, executeAsync, isExecutable, keepStatement, poolable, queryTimeout
-
Method Details
-
onConflictOnConstraint
@NotNull @CheckReturnValue @Support({AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,DUCKDB,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,YUGABYTEDB}) @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Constraint constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement. -
onConflictOnConstraint
@NotNull @CheckReturnValue @Support({AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,DUCKDB,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,YUGABYTEDB}) @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(Name constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement. -
onConflictOnConstraint
@NotNull @CheckReturnValue @Support @NotNull InsertOnConflictDoUpdateStep<R> onConflictOnConstraint(UniqueKey<R> constraint) Add aON CONFLICT ON CONSTRAINT
clause to this INSERT statement. -
onConflict
@NotNull @CheckReturnValue @Support @NotNull InsertOnConflictWhereIndexPredicateStep<R> onConflict(Field<?>... keys) Add anON CONFLICT
clause to this INSERT statement.Only
SQLDialect.POSTGRES
andSQLDialect.SQLITE
have native support for this clause. The other dialects can emulate it usingMERGE
, if table meta data is available. -
onConflict
@NotNull @CheckReturnValue @Support @NotNull InsertOnConflictWhereIndexPredicateStep<R> onConflict(Collection<? extends Field<?>> keys) Add anON CONFLICT
clause to this INSERT statement.Only
SQLDialect.POSTGRES
andSQLDialect.SQLITE
have native support for this clause. The other dialects can emulate it usingMERGE
, if table meta data is available. -
onConflictDoNothing
Add anON CONFLICT DO NOTHING
clause to this INSERT statement.Only
SQLDialect.POSTGRES
andSQLDialect.SQLITE
have native support for this clause. The other dialects can emulate it usingMERGE
, if table meta data is available. -
onDuplicateKeyUpdate
@NotNull @CheckReturnValue @Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,DUCKDB,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) @NotNull InsertOnDuplicateSetStep<R> onDuplicateKeyUpdate()Add anON 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 thisINSERT
statement's affected table that matches the value being inserted, then theUPDATE
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:- The
INSERT
statement's table is aTable
with aTable.getPrimaryKey()
- The RDBMS supports the
MERGE
clause (seeDSLContext.mergeInto(Table)
).
H2 supports this clause in MySQL mode.
- The
-
onDuplicateKeyIgnore
Add anON 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 thisINSERT
statement's affected table that matches the value being inserted, then theINSERT
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
andSQLDialect.MARIADB
INSERT IGNORE INTO …
SQLDialect.POSTGRES_9_5
andSQLDialect.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] )
-