Hi Lukas,
I am designing a DB where I have the columns below.
There is a nightly build which is basically pulling data from another system and entering records to this DB. I am doing a batch insert of records.
public boolean createTopicPages(List<TopicPage> topicPages) {
List<TopicPageRecord> topicPageRecords = new ArrayList<>(topicPages.size());
topicPages.stream().forEach(topicPage -> {
TopicPageRecord topicPageRecord = new TopicPageRecord();
topicPageRecord.setTaxonomyId(topicPage.getTaxonomyId());
topicPageRecord.setCmsName(topicPage.getCmsName());
topicPageRecord.setSubject(topicPage.getSubject());
topicPageRecord.setClassification(topicPage.getClassification());
topicPageRecord.setEntryName(topicPage.getEntryName());
topicPageRecord.setStatus(topicPage.getStatus());
topicPageRecord.setEntryUpdated(topicPage.getEntryUpdated());
topicPageRecord.setEntryPublished(topicPage.getEntryPublished());
topicPageRecords.add(topicPageRecord);
});
int[] execute = dsl.batchInsert(topicPageRecords).execute();
return execute.length > 0;
}
Now the problem is, when every time pull records and trying to insert into the DB , there will be exiting entries already in the DB. I wanted to either ignore or update the existing records.
If there is a change to either entry_updated OR status for any of the existing records in DB then I wanted to update that record with the new status and entry_updated value. Otherwise ignore those existing records and just insert the new ones.
In my DB cms_name, taxonomy_id & subject are unique columns.
Can you please let me know how will I solve this problem using Jooq query ? I was reading lot of blogs where people are talking about upsert solutions which you have provided but in my case its a batch insert I am doing so in that case how Jooq will help me here.
NOTE: I use Postgres DB for my application.
Thanks,
Deba