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?
1 REPLY
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