- Type Parameters:
- R- The record type of the table being inserted into
- All Superinterfaces:
- Attachable,- AttachableQueryPart,- ConditionProvider,- DMLQuery<R>,- Flow.Publisher<Integer>,- Insert<R>,- Publisher<Integer>,- org.reactivestreams.Publisher<Integer>,- Query,- QueryPart,- RowCountQuery,- Serializable,- Statement,- StoreQuery<R>
INSERT statement (model API).
 
 This type is the model API representation of a Insert statement,
 which can be mutated after creation. The advantage of this API compared to
 the DSL API is a more simple approach to writing dynamic SQL.
 
 Instances can be created using DSLContext.insertQuery(Table) and
 overloads.
- Author:
- Lukas Eder
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddConditions(Collection<? extends Condition> conditions) Adds new conditions to the query, connecting them to existing conditions withOperator.AND.voidaddConditions(Condition condition) Adds a new condition to the query, connecting it to existing conditions withOperator.AND.voidaddConditions(Condition... conditions) Adds new conditions to the query, connecting them to existing conditions withOperator.AND.voidaddConditions(Operator operator, Collection<? extends Condition> conditions) Adds new conditions to the query, connecting them to existing conditions with the provided operator.voidaddConditions(Operator operator, Condition condition) Adds a new condition to the query, connecting it to existing conditions with the provided operator.voidaddConditions(Operator operator, Condition... conditions) Adds new conditions to the query, connecting them to existing conditions with the provided operator.voidShort for callingnewRecord(); setRecord(record);<T> voidaddValueForUpdate(Field<T> field, Field<T> value) Add a value to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.<T> voidaddValueForUpdate(Field<T> field, T value) Add a value to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.voidaddValuesForUpdate(Map<?, ?> map) Add multiple values to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.The record holding returned values as specified by any of theStoreQuery.setReturning()methods.The records holding returned values as specified by any of theStoreQuery.setReturning()methods.voidAdds a new Record to the insert statement for multi-record insertsvoidonConflict(Collection<? extends Field<?>> fields) Whether aON CONFLICTclause should be added to thisINSERTstatement.voidonConflict(Field<?>... fields) Whether aON CONFLICTclause should be added to thisINSERTstatement.voidonConflictOnConstraint(Constraint constraint) Whether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.voidonConflictOnConstraint(Name constraint) Whether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.voidonConflictOnConstraint(UniqueKey<R> constraint) Whether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.voidonConflictWhere(Condition condition) Adds a new condition theonConflict(Field...)clause.voidonDuplicateKeyIgnore(boolean flag) Whether anON DUPLICATE KEY IGNOREclause should be added to thisINSERTstatement.voidonDuplicateKeyUpdate(boolean flag) Whether aON DUPLICATE KEY UPDATEclause should be added to thisINSERTstatement.voidSet an empty record with theDEFAULT VALUESclause.voidConfigure theINSERTorUPDATEstatement to return all fields inR.voidsetReturning(Collection<? extends SelectFieldOrAsterisk> fields) Configure theINSERTorUPDATEstatement to return a list of fields inR.voidsetReturning(Identity<R, ?> identity) Configure theINSERTorUPDATEstatement to return the generated identity value.voidsetReturning(SelectFieldOrAsterisk... fields) Configure theINSERTorUPDATEstatement to return a list of fields inR.voidsetSelect(Collection<? extends Field<?>> fields, Select<?> select) Use aSELECTstatement as the source of values for theINSERTstatement.voidUse aSELECTstatement as the source of values for theINSERTstatement.Methods inherited from interface org.jooq.Attachableattach, configuration, detachMethods inherited from interface org.jooq.AttachableQueryPartgetBindValues, getParam, getParams, getSQL, getSQLMethods inherited from interface org.reactivestreams.PublishersubscribeMethods inherited from interface org.jooq.Querybind, bind, cancel, execute, executeAsync, executeAsync, isExecutable, keepStatement, poolable, queryTimeout
- 
Method Details- 
newRecordAdds a new Record to the insert statement for multi-record insertsCalling this method will cause subsequent calls to StoreQuery.addValue(Field, Object)(and similar) to fill the next record.If this call is not followed by StoreQuery.addValue(Field, Object)calls, then this call has no effect.If this call is done on a fresh insert statement (without any values yet), then this call has no effect either. 
- 
addRecordShort for callingnewRecord(); setRecord(record);- Parameters:
- record- The record to add to this insert statement.
 
- 
onConflictWhether aON CONFLICTclause should be added to thisINSERTstatement.When setting this flag to true, be sure to also add values "for update" using theaddValueForUpdate(Field, Field)methods.
- 
onConflictWhether aON CONFLICTclause should be added to thisINSERTstatement.When setting this flag to true, be sure to also add values "for update" using theaddValueForUpdate(Field, Field)methods.
- 
onConflictOnConstraint@Support({AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,YUGABYTEDB}) void onConflictOnConstraint(Name constraint) Whether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.
- 
onConflictOnConstraint@Support({AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLSERVER,SYBASE,YUGABYTEDB}) void onConflictOnConstraint(Constraint constraint) Whether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.
- 
onConflictOnConstraintWhether use aON CONFLICTorON CONFLICT ON CONSTRAINTclause in thisINSERTstatement.
- 
onDuplicateKeyUpdate@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) void onDuplicateKeyUpdate(boolean flag) Whether aON DUPLICATE KEY UPDATEclause should be added to thisINSERTstatement.When setting this flag to true, be sure to also add values "for update" using theaddValueForUpdate(Field, Field)methods.The ON DUPLICATE KEY UPDATEflag is mutually exclusive with theON DUPLICATE KEY IGNOREflag (seeonDuplicateKeyIgnore(boolean). Setting one will unset the other
- 
onDuplicateKeyIgnoreWhether anON DUPLICATE KEY IGNOREclause should be added to thisINSERTstatement.This clause is not actually supported in this form by any database, but can be emulated as such: Dialect Emulation SQLDialect.MYSQLandSQLDialect.MARIADBINSERT IGNORE INTO …SQLDialect.POSTGRES_9_5andSQLDialect.SQLITEINSERT INTO … ON CONFLICT DO NOTHINGSQLDialect.DB2
 SQLDialect.HSQLDB
 SQLDialect.ORACLE
 SQLDialect.SQLSERVER
 SQLDialect.SYBASEMERGE 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] )The ON DUPLICATE KEY UPDATEflag is mutually exclusive with theON DUPLICATE KEY IGNOREflag (seeonDuplicateKeyIgnore(boolean). Setting one will unset the other
- 
addValueForUpdate@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) <T> void addValueForUpdate(Field<T> field, T value) Add a value to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.
- 
addValueForUpdate@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) <T> void addValueForUpdate(Field<T> field, Field<T> value) Add a value to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.
- 
addValuesForUpdate@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD_3_0,H2,HANA,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) void addValuesForUpdate(Map<?, ?> map) Add multiple values to theON DUPLICATE KEY UPDATEclause of thisINSERTstatement, where this is supported.Please assure that key/value pairs have matching <T>types. Values can either be of type<T>orField<T>
- 
onConflictWhere@Support({AURORA_POSTGRES,POSTGRES_9_5,SQLITE,YUGABYTEDB}) void onConflictWhere(Condition condition) Adds a new condition theonConflict(Field...)clause.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Parameters:
- condition- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Condition condition) Adds a new condition to the query, connecting it to existing conditions withOperator.AND.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- condition- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Condition... conditions) Adds new conditions to the query, connecting them to existing conditions withOperator.AND.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- conditions- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Collection<? extends Condition> conditions) Adds new conditions to the query, connecting them to existing conditions withOperator.AND.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- conditions- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Operator operator, Condition condition) Adds a new condition to the query, connecting it to existing conditions with the provided operator.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- condition- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Operator operator, Condition... conditions) Adds new conditions to the query, connecting them to existing conditions with the provided operator.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- conditions- The condition
 
- 
addConditions@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DERBY,EXASOL,H2,HANA,MARIADB,MYSQL,ORACLE,POSTGRES_9_5,SNOWFLAKE,SQLITE,SQLSERVER,YUGABYTEDB}) void addConditions(Operator operator, Collection<? extends Condition> conditions) Adds new conditions to the query, connecting them to existing conditions with the provided operator.This is for use with SQLDialect.POSTGRES'sonConflict(Field...)clause.- Specified by:
- addConditionsin interface- ConditionProvider
- Parameters:
- conditions- The condition
 
- 
setDefaultValues@Support({ASE,AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,EXASOL,FIREBIRD,H2,HSQLDB,INGRES,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES,SQLDATAWAREHOUSE,SQLITE,SQLSERVER,SYBASE,TERADATA,YUGABYTEDB}) void setDefaultValues()Set an empty record with theDEFAULT VALUESclause.
- 
setSelectUse aSELECTstatement as the source of values for theINSERTstatement.
- 
setSelectUse aSELECTstatement as the source of values for theINSERTstatement.
- 
setReturningConfigure theINSERTorUPDATEstatement to return all fields inR.This feature works with INSERTstatements for all SQL dialects- Specified by:
- setReturningin interface- StoreQuery<R extends Record>
- See Also:
 
- 
setReturningConfigure theINSERTorUPDATEstatement to return the generated identity value.This feature works with INSERTstatements for all SQL dialects- Specified by:
- setReturningin interface- StoreQuery<R extends Record>
- Parameters:
- identity- The table's identity
- See Also:
 
- 
setReturningConfigure theINSERTorUPDATEstatement to return a list of fields inR.This feature works with INSERTstatements for all SQL dialects- Specified by:
- setReturningin interface- StoreQuery<R extends Record>
- Parameters:
- fields- Fields to be returned
- See Also:
 
- 
setReturningConfigure theINSERTorUPDATEstatement to return a list of fields inR.This feature works with INSERTstatements for all SQL dialects- Specified by:
- setReturningin interface- StoreQuery<R extends Record>
- Parameters:
- fields- Fields to be returned
- See Also:
 
- 
getReturnedRecordThe record holding returned values as specified by any of theStoreQuery.setReturning()methods.If the insert statement returns several records, this is the same as calling getReturnedRecords().get(0)This implemented differently for every dialect: - Firebird and Postgres have native support for
 INSERT … RETURNINGandUPDATE … RETURNINGclauses
- HSQLDB, Oracle, and DB2 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
 @@identityorlast_inserted_rowid()values. Those values are fetched in a separateSELECTstatement. If other fields are requested, a second statement is issued. Client code must assure transactional integrity between the two statements.
 This feature works with INSERTstatements for all SQL dialects- Specified by:
- getReturnedRecordin interface- StoreQuery<R extends Record>
- Returns:
- The returned value as specified by any of the
         StoreQuery.setReturning()methods. This may returnnullin case jOOQ could not retrieve any generated keys from the JDBC driver.
- See Also:
 
- Firebird and Postgres have native support for
 
- 
getReturnedRecordsThe records holding returned values as specified by any of theStoreQuery.setReturning()methods.This implemented differently for every dialect: - Firebird and Postgres have native support for
 INSERT … RETURNINGandUPDATE … RETURNINGclauses
- HSQLDB, Oracle, and DB2 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
 @@identityorlast_inserted_rowid()values. Those values are fetched in a separateSELECTstatement. If other fields are requested, a second statement is issued. Client code must assure transactional integrity between the two statements.
 [#5070] Due to an early API design flaw, this method historically returns the type R, not a more generic typeRecord. This means that only actual columns inRcan be returned. For a more generic set of column expressions, useStoreQuery.getResult()instead.This feature works with INSERTstatements for all SQL dialects- Specified by:
- getReturnedRecordsin interface- StoreQuery<R extends Record>
- Returns:
- The returned values as specified by any of the
         StoreQuery.setReturning()methods. Note:- Not all databases / JDBC drivers support returning several values on multi-row inserts!
- This may return an empty Resultin case jOOQ could not retrieve any generated keys from the JDBC driver.
 
 
- Firebird and Postgres have native support for
 
 
-