Hi Samir,

I'm sorry for the delay.

dsl.batchInsert(records).onDuplicateKeyUpdate()
> .set(Table.Field, TableRecord.getField)
> .set(Table.AnotherField, TableRecord.getAnotherField)
> .execute();


Currently, this isn't possible out of the box. There's a pending feature
request for this, here:
https://github.com/jOOQ/jOOQ/issues/3172

But you should be able to batch your explicit INSERT .. ON DUPLICATE KEY
UPDATE statements

Either ways, my wish list aside, neither pattern seems to work with Jooq
> 3.8.1 (Or I'm passing in the wrong data type).  Is there a supported
> pattern that does work?
> Or can upserts not be done in conjunction with batch operations?


What went wrong?

Lukas

2016-10-20 3:34 GMT+02:00 Samir Faci <[email protected]>:

> Just for reference, simple upsert work fine, using something along these
> lines.  Snippet below is my preferred pattern, mergeInto is less verbose,
> but our PKeys don't actually mean primary key at times so being explicit is
> necessary.
>
> this.ctx().insertInto(this.table())
>     .set(DSL.field("id"), f.id())
>     .set(DSL.field("last_modified"), Timestamp.from(Instant.now()))
>    * .onDuplicateKeyUpdate()*
>     .set(DSL.field("last_modified"), Timestamp.from(Instant.now())))
>
>
> What I'm trying to do is take advantage of postgres upsert operation and
> use batch operations.
>
> Ideally I would love something along these lines to work.
>
> List<SomeTableRecord> records = Lists.newArrayList();
> // build up a list of recrods...
>
>
> dsl.batchInsert(records).onDuplicateKeyUpdate()
> .set(Table.Field, TableRecord.getField)
> .set(Table.AnotherField, TableRecord.getAnotherField)
> .execute();
>
> Failing that, is there support for batch operation with upserts?
>
> I was also trying to use this pattern:
>
> create.batch(
>       create.insertInto(AUTHOR, ID, FIRST_NAME, LAST_NAME).values(1, "Erich"  
> , "Gamma"    ),
>       create.insertInto(AUTHOR, ID, FIRST_NAME, LAST_NAME).values(2, 
> "Richard", "Helm"     ),
>       create.insertInto(AUTHOR, ID, FIRST_NAME, LAST_NAME).values(3, "Ralph"  
> , "Johnson"  ),
>       create.insertInto(AUTHOR, ID, FIRST_NAME, LAST_NAME).values(4, "John"   
> , "Vlissides")).execute();
>
>
>
> It would be great if I can write something along the lines of:
>
> List<InsertOnDuplicateSetMoreStep<TableRecord>> queries = 
> Lists.newArrayList();
>
> InsertOnDuplicateSetMoreStep<TableRecord> query = 
> this.ctx().insertInto(this.table())
>
>     .set(DSL.field("id"), f.id())
>     .set(DSL.field("last_modified"), Timestamp.from(Instant.now()))
>    * .onDuplicateKeyUpdate()*
>     .set(DSL.field("last_modified"), Timestamp.from(Instant.now())))
>
> queries.add(query);
>
> Build up a List of these query and then simply execute something along the
> lines of:
>
> create.batch( queryList).execute();
>
>
>
> Either ways, my wish list aside, neither pattern seems to work with Jooq
> 3.8.1 (Or I'm passing in the wrong data type).  Is there a supported
> pattern that does work?
> Or can upserts not be done in conjunction with batch operations?
>
>
> --
> Thank you
> Samir Faci
> https://keybase.io/csgeek
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to