<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Insert or update with ID from context (that can be null) in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259171#M40732</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I would like to insert or update datas in a database depending on the value of the ID available in my context. (see screenshots below)&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tmap.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Ed.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/151557i0FD7075910D9F06B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Ed.png" alt="0683p000009M1Ed.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;2&amp;nbsp;cases :&lt;/P&gt; 
&lt;UL&gt; 
 &lt;LI&gt;My ID (context.asset_id) is not null so it exists in the output table =&amp;gt;&amp;nbsp;update =&amp;gt; working well&lt;/LI&gt; 
 &lt;LI&gt;My ID (context.asset_id) is null =&amp;gt; insert (using auto_increment on the ID which has been enabled) =&amp;gt; throw an exception&lt;/LI&gt; 
&lt;/UL&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="exception.png" style="width: 620px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Vr.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/136864i71A80D8B5D38A0C4/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Vr.png" alt="0683p000009M1Vr.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="line.png" style="width: 587px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Vw.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/150669iD752702EE9E3DD7E/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Vw.png" alt="0683p000009M1Vw.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;At the moment, in order to make it works, I'm using two different jobs (one for updates and one for inserts) and a tFilterRow which switch null id's to insert job and not null id's to update job. The problem is both jobs are quite identical so that's not really clean ...&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How could I make it work as I wish? &lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Nov 2018 15:27:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-11-19T15:27:00Z</dc:date>
    <item>
      <title>Insert or update with ID from context (that can be null)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259171#M40732</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I would like to insert or update datas in a database depending on the value of the ID available in my context. (see screenshots below)&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tmap.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Ed.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/151557i0FD7075910D9F06B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Ed.png" alt="0683p000009M1Ed.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;2&amp;nbsp;cases :&lt;/P&gt; 
&lt;UL&gt; 
 &lt;LI&gt;My ID (context.asset_id) is not null so it exists in the output table =&amp;gt;&amp;nbsp;update =&amp;gt; working well&lt;/LI&gt; 
 &lt;LI&gt;My ID (context.asset_id) is null =&amp;gt; insert (using auto_increment on the ID which has been enabled) =&amp;gt; throw an exception&lt;/LI&gt; 
&lt;/UL&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="exception.png" style="width: 620px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Vr.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/136864i71A80D8B5D38A0C4/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Vr.png" alt="0683p000009M1Vr.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="line.png" style="width: 587px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1Vw.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/150669iD752702EE9E3DD7E/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1Vw.png" alt="0683p000009M1Vw.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;At the moment, in order to make it works, I'm using two different jobs (one for updates and one for inserts) and a tFilterRow which switch null id's to insert job and not null id's to update job. The problem is both jobs are quite identical so that's not really clean ...&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How could I make it work as I wish? &lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 15:27:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259171#M40732</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-19T15:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Insert or update with ID from context (that can be null)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259172#M40733</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Update and Insert are two distinct operations: why do you want to combine the jobs? It sounds like more trouble than it's worth.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How is the job handling null values for the ID field now?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 20:58:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259172#M40733</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-19T20:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Insert or update with ID from context (that can be null)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259173#M40734</link>
      <description>&lt;P&gt;I would like to combine these two jobs because they are identical and it doubles the cost of maintenance if a modification need to be done...&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Null values are not handled at all, let me explain you how it works.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I have a table with two ID's columns (ID from old db, ID from new db). I read each row of this table and 2 cases are possible:&lt;/P&gt; 
&lt;OL&gt; 
 &lt;LI&gt;if ID from new db is not null then I update datas&amp;nbsp;by using&amp;nbsp;the ones from old db.&lt;/LI&gt; 
 &lt;LI&gt;if ID from new db is null then I insert datas from old db to new db.&lt;/LI&gt; 
&lt;/OL&gt; 
&lt;P&gt;I use a tFilterRow to switch on the value of the ID (Not null =&amp;gt; update job, null =&amp;gt; insert job).&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The only difference between these 2 jobs is in the tMap before insert or update datas (tDBOutput). If I am inside inserting job then the field ID is left empty, if I am inside updating job then the field ID is filled.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 08:15:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259173#M40734</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-20T08:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Insert or update with ID from context (that can be null)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259174#M40735</link>
      <description>&lt;P&gt;I'm assuming the new records have an auto-increment ID field, so that you just need to handle the NullPointer exception, and not generate a new unique ID, correct? If so, you could&amp;nbsp;test the ID field in tMap to see if it's empty, and if it is, assign a placeholder value to avoid the exception. You might be able to use Java's isNull() function; something like (in the tMap expression for the ID field):&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row1.ID.isNull() ? "123" : row1.ID&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The "123" can be any value, since you're just going to discard it. If isNull() doesn't work (sometimes it doesn't), then try comparing to the empty string:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row1.ID.equals("") ? "123" :row1.ID&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If ID is a number, then:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row1.ID == "" ? 123 : row1.ID&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 13:13:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259174#M40735</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-20T13:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Insert or update with ID from context (that can be null)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259175#M40736</link>
      <description>&lt;P&gt;Yes,&amp;nbsp;as you assume, I have an auto-incrementing ID inside my new table but what do you mean by using any value which will be discarded ? If I fill the ID field with any value, it will try to insert a row with this ID, or even try to update a row with this ID (supposing I have defined the action "insert or update" on the table).&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 14:11:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Insert-or-update-with-ID-from-context-that-can-be-null/m-p/2259175#M40736</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-20T14:11:15Z</dc:date>
    </item>
  </channel>
</rss>

