<?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 Upsert When the Origin NOT Exists, but you need to change status in the target in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7777#M3551</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question about upsert/merge ...&amp;nbsp;What do you do when que origin NOT exists, but you need to change status in the target&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​For exemple:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01/03 : source dataset [ id =1 and status = Active] ; target table [*not exists*] &amp;gt;&amp;gt; in this time&amp;nbsp;the upsert/merge add the source record in&amp;nbsp;target table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​​02/03: source dataset [ id = 1 and status = Wait] ; target table [id =1 and status = Active] &amp;gt;&amp;gt; in this time&amp;nbsp;the upsert/merge change the status record in targe table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​​03/03: source dataset [ * id = 1, it disappeared in source *] ; target table [id =1 and status = Deactivate] &amp;gt;&amp;gt; in this time the upsert/merge not found id = 1 in the source and can`t the change status in target table, but I need to change the status of record to 'Deactivate'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have any idea ?&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 00:54:17 GMT</pubDate>
    <dc:creator>William_Scardua</dc:creator>
    <dc:date>2023-03-14T00:54:17Z</dc:date>
    <item>
      <title>Upsert When the Origin NOT Exists, but you need to change status in the target</title>
      <link>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7777#M3551</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question about upsert/merge ...&amp;nbsp;What do you do when que origin NOT exists, but you need to change status in the target&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​For exemple:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01/03 : source dataset [ id =1 and status = Active] ; target table [*not exists*] &amp;gt;&amp;gt; in this time&amp;nbsp;the upsert/merge add the source record in&amp;nbsp;target table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​​02/03: source dataset [ id = 1 and status = Wait] ; target table [id =1 and status = Active] &amp;gt;&amp;gt; in this time&amp;nbsp;the upsert/merge change the status record in targe table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​​03/03: source dataset [ * id = 1, it disappeared in source *] ; target table [id =1 and status = Deactivate] &amp;gt;&amp;gt; in this time the upsert/merge not found id = 1 in the source and can`t the change status in target table, but I need to change the status of record to 'Deactivate'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have any idea ?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 00:54:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7777#M3551</guid>
      <dc:creator>William_Scardua</dc:creator>
      <dc:date>2023-03-14T00:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Upsert When the Origin NOT Exists, but you need to change status in the target</title>
      <link>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7778#M3552</link>
      <description>&lt;P&gt;Hi @William Scardua​&amp;nbsp;Delta table gives you the option where you can match with either source or target table and decide the possible action on your target table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try to use the below approach and let us know it this meets your requirement. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;-- Delete all target rows that have no matches in the source table.
&amp;gt; MERGE INTO target USING source
  ON target.key = source.key
  WHEN NOT MATCHED BY SOURCE THEN DELETE
&amp;nbsp;
-- Multiple NOT MATCHED BY SOURCE clauses conditionally deleting unmatched target rows and updating two columns for all other matched rows.
&amp;gt; MERGE INTO target USING source
  ON target.key = source.key
  WHEN NOT MATCHED BY SOURCE AND target.marked_for_deletion THEN DELETE
  WHEN NOT MATCHED BY SOURCE THEN UPDATE SET target.value = DEACTIVATE&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vignesh&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 07:52:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7778#M3552</guid>
      <dc:creator>pvignesh92</dc:creator>
      <dc:date>2023-03-14T07:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Upsert When the Origin NOT Exists, but you need to change status in the target</title>
      <link>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7779#M3553</link>
      <description>&lt;P&gt;Hello @William Scardua​&amp;nbsp;, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just adding to what @Vigneshraja Palaniraj​&amp;nbsp;replied.&lt;/P&gt;&lt;P&gt;Reference: &lt;A href="https://docs.databricks.com/sql/language-manual/delta-merge-into.html" target="test_blank"&gt;https://docs.databricks.com/sql/language-manual/delta-merge-into.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Nandini&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 12:23:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7779#M3553</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2023-03-14T12:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Upsert When the Origin NOT Exists, but you need to change status in the target</title>
      <link>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7780#M3554</link>
      <description>&lt;P&gt;Thank you @Vigneshraja Palaniraj​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this I need to change the my cluster version, but thank you man&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:29:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/upsert-when-the-origin-not-exists-but-you-need-to-change-status/m-p/7780#M3554</guid>
      <dc:creator>William_Scardua</dc:creator>
      <dc:date>2023-03-14T13:29:38Z</dc:date>
    </item>
  </channel>
</rss>

