Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
sushantV
Creator
Creator

tMap - Insertion to mySQL based on composite key

I need to read data from a raw file and insert into a MySQL table. However, my target table is unique only at combination of two fields. I do not have the option to create a composite key in the target table. 

 

Is there a way I can do the update or insert, based on this key combination? Essentially I am trying to understand how the multilevel key mapping happens in the tMap component.

Labels (2)
3 Replies
ThWabi
Creator II
Creator II

Hi sushantV,

 

in tMap, on the output panel you can define multiple columns to be key columns.

For example: 

 

0683p000009LzR1.jpg

 

 

Best regards,

 

Thomas

sushantV
Creator
Creator
Author

I thought so however I am still confused about the interpretation. If I provide two key columns in the tMap (on both sides), would Talend create a temp composite key and process the records based on combination of both the keys? 

 

Further extending my question, what happens if I select two key columns on one side and just one key column on another. How would the system interpret?

 

My task is either insert or update, based on the pre-existence of the match key (which is a combination of two columns)

ThWabi
Creator II
Creator II

Hi sushantV,

 

I think the Key columns are only used for SQL update or delete statements.

 

  • For an insert, Talend generates an SQL statement like 
    insert into mytable (customer_name, country, value) values ('Smith', 'Germany', 123);
    If customer_name and country are defined as the primary keys in the database table, the database will make sure that the combination of 'Smith' and 'Germany' is unique.
  • For an update, Talend generates an SQL statement like
    update mytable set value = 123 where customer_name = 'Smith' and country = 'Germany'
    The Key columns are used in the where clause (to uniquely determine which row should be updated).

 

@sushantV wrote:

 

[...] what happens if I select two key columns on one side and just one key column on another. 


It depends on how you (want to) connect the input side to the output side. You can calculate one unique key for the output panel from the two keys on your input panel.

 

Best regards,

 

Thomas