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())))
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();
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);
create.batch( queryList).execute();
dsl.batchInsert(records).onDuplicateKeyUpdate()
.set(Table.Field, TableRecord.getField)
.set(Table.AnotherField, TableRecord.getAnotherField)
.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?
--
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 jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
insert into pinned_tweets (user_handle, tweet_id, pinned_at)
values (
'rey',
1,
clock_timestamp()
)
on conflict (user_handle)
do update set (tweet_id, pinned_at) = (1, clock_timestamp())
where pinned_tweets.user_handle = 'rey';
Actually, the the second approach does work, though I was running into a different issue because the "primary key" in my case is serial ID which doesn't work well with upserts.I was wondering if there was a way to explicitly list the columns I want to use for upserts.Example:insert into pinned_tweets (user_handle, tweet_id, pinned_at) values ( 'rey', 1, clock_timestamp() ) on conflict (user_handle) do update set (tweet_id, pinned_at) = (1, clock_timestamp()) where pinned_tweets.user_handle = 'rey';
(Pulled from a random blog)
But I believe any valid Index or constrain can be applied (Postgres). Can we add a method that takes a .onConflict(Index_name or constraint_name) ?
I'm assuming jooq can auto-gen indexes as well?
Hi Samir,2016-10-31 20:11 GMT+01:00 Samir Faci <sa...@esamir.com>:Actually, the the second approach does work, though I was running into a different issue because the "primary key" in my case is serial ID which doesn't work well with upserts.I was wondering if there was a way to explicitly list the columns I want to use for upserts.Example:insert into pinned_tweets (user_handle, tweet_id, pinned_at) values ( 'rey', 1, clock_timestamp() ) on conflict (user_handle) do update set (tweet_id, pinned_at) = (1, clock_timestamp()) where pinned_tweets.user_handle = 'rey';
(Pulled from a random blog)Hmm, PostgreSQL ON CONFLICT will be supported in jOOQ 3.9:Prior to 3.9, ON CONFLICT is already emulated via MySQL's ON DUPLICATE KEY UPDATE syntax, in case of which the primary key (from your generated table) will be passed to the ON CONFLICT clause.Let me know if this works for you.
But I overlooked that WHERE clause. Added another feature request for this:But do you need it in your example?
But I believe any valid Index or constrain can be applied (Postgres). Can we add a method that takes a .onConflict(Index_name or constraint_name) ?Yes, in jOOQ 3.9.
I'm assuming jooq can auto-gen indexes as well?No, we don't generate indexes yet as that information hasn't been useful to general jOOQ API usage (yet).
Best Regards,Lukas
--
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 jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yup. That's what I was using. The issue I was running into was that the PKey was not useful, so I needed to specify a unique constraint/index. It looks like that will be supported in 3.9.
I don't think I need to use the where clause. Though I imagine it would be a useful pattern.
The two main Upsert + Jooq features I would love to see are:1. batch operation working with upserts (which is partially supported by generating a list of custom insert statements)2. the ability to specify the list of columns rather the .onKeyConflict which doesn't support all of my use cases.
No, we don't generate indexes yet as that information hasn't been useful to general jOOQ API usage (yet).That's fine. I suppose there's not much usability added by having java objects generated for them.
2016-11-02 4:29 GMT+01:00 Samir Faci <sa...@esamir.com>:Yup. That's what I was using. The issue I was running into was that the PKey was not useful, so I needed to specify a unique constraint/index. It looks like that will be supported in 3.9.I'm curious about this to learn more about your use-case. Why was the primary key not useful in your case?
I don't think I need to use the where clause. Though I imagine it would be a useful pattern.Yes indeed. Sometimes, it's safe to ignore failed inserts rather than performing some update. Especially when inserting a whole data set, this is a useful pattern, which is also available from the SQL standard MERGE statement.
I keep wondering why PostgreSQL didn't just implement MERGE, though.The two main Upsert + Jooq features I would love to see are:1. batch operation working with upserts (which is partially supported by generating a list of custom insert statements)2. the ability to specify the list of columns rather the .onKeyConflict which doesn't support all of my use cases.Regarding 2), this is the jOOQ 3.9 API:/*** Add an <code>ON CONFLICT</code> clause to this insert query.*/@Support({ POSTGRES_9_5 })InsertOnConflictDoUpdateStep<R> onConflict(Field<?>... keys);/*** Add an <code>ON CONFLICT</code> clause to this insert query.*/@Support({ POSTGRES_9_5 })InsertOnConflictDoUpdateStep<R> onConflict(Collection<? extends Field<?>> keys);No, we don't generate indexes yet as that information hasn't been useful to general jOOQ API usage (yet).That's fine. I suppose there's not much usability added by having java objects generated for them.Well, there is now that we support DDL to create indexes or to restore a schema from jOOQ classes :)There, I've added a feature request so this won't be forgotten (in particular: ON CONFLICT usage with index names):
Thanks,Lukas
--
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 jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.