Define unique key on Talend side

One Star

Define unique key on Talend side

Hi
I have the following task: MySQL Table target table which contains data which should be unique if some conditions are met and not otherwise. So, unique constraint can not be enforced on the MySQL side.
Data are loaded in 2 phases, first for unique data part and then for other.
For unique data part I define local schema for source marking unique fields combination as a key and then do the same for the target output.
Set Action on data to insert.
The expectation was that record should not be inserted if groups of values defined in key already exists in DB. But the record is inserted.
So the questions are: what is the meaning of key attribute in the schema if it does not enforce any constraint? How data can be updated instead of inserted in case unique constraint is not enforced in DB?
Community Manager

Re: Define unique key on Talend side

Hi
The key attribute in the schema is used for update action, there must be at least one column as a key for update. For example, there exist three records in target table:
id;name;age
1;shong;11
2;elise;22
3;plegall;33
Now, two rows will be inserted or update into the target table, the action is 'insert or update', check the key attribute on id column.
1;newshong;11
4;mike;44
After running the job, the target table will be:
1;newshong;11
2;elise;22
3;plegall;33
4;mike;44
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog