org.jooq
Interface InsertOnDuplicateStep<R extends Record>

All Superinterfaces:
Adapter, Attachable, Insert<R>, InsertFinalStep<R>, InsertReturningStep<R>, Query, QueryPart, Serializable
All Known Subinterfaces:
InsertSetMoreStep<R>, InsertValuesStep<R>

public interface InsertOnDuplicateStep<R extends Record>
extends InsertFinalStep<R>, InsertReturningStep<R>

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

Example:

 Factory create = new Factory();

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

Author:
Lukas Eder

Method Summary
 InsertFinalStep<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.
 
Methods inherited from interface org.jooq.Query
bind, bind, execute, getBindValues, getParam, getParams, getSQL, getSQL, isExecutable
 
Methods inherited from interface org.jooq.QueryPart
attach
 
Methods inherited from interface org.jooq.Adapter
internalAPI
 
Methods inherited from interface org.jooq.InsertReturningStep
returning, returning, returning
 

Method Detail

onDuplicateKeyUpdate

InsertOnDuplicateSetStep<R> onDuplicateKeyUpdate()
Add an 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 simulate this clause using a MERGE statement on some other databases. The conditions for a RDBMS to simulate this clause are:

These are the dialects that fulfill the above requirements:


onDuplicateKeyIgnore

InsertFinalStep<R> onDuplicateKeyIgnore()
Add an 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 simulated as such:

Dialect Simulation
SQLDialect.MYSQL
INSERT IGNORE INTO ..
SQLDialect.CUBRID
INSERT INTO .. ON DUPLICATE KEY UPDATE [any-field] = [any-field]
SQLDialect.DB2
SQLDialect.HSQLDB
SQLDialect.ORACLE
SQLDialect.SQLSERVER
SQLDialect.SYBASE
MERGE INTO [dst]
 USING ([values]) src
 ON [dst.key] = [src.key]
 WHEN NOT MATCHED THEN INSERT ..



Copyright © 2012. All Rights Reserved.