<?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 PKEY Upserting Pattern With Older Runtimes in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/98997#M39884</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm aware that nowadays newer runtimes of Databricks support some great features, including primary and foreign key constraints. I'm wondering, if we have clusters that are running older runtime versions, are there Upserting patterns that have been used before and may be recommended?&lt;/P&gt;&lt;P&gt;For additional context, our clusters are mainly in Runtime 13.3 and we do have one running 14.1.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 02:06:49 GMT</pubDate>
    <dc:creator>ChristianRRL</dc:creator>
    <dc:date>2024-11-16T02:06:49Z</dc:date>
    <item>
      <title>PKEY Upserting Pattern With Older Runtimes</title>
      <link>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/98997#M39884</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm aware that nowadays newer runtimes of Databricks support some great features, including primary and foreign key constraints. I'm wondering, if we have clusters that are running older runtime versions, are there Upserting patterns that have been used before and may be recommended?&lt;/P&gt;&lt;P&gt;For additional context, our clusters are mainly in Runtime 13.3 and we do have one running 14.1.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 02:06:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/98997#M39884</guid>
      <dc:creator>ChristianRRL</dc:creator>
      <dc:date>2024-11-16T02:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: PKEY Upserting Pattern With Older Runtimes</title>
      <link>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/99393#M39982</link>
      <description>&lt;P class="_1t7bu9h1 paragraph"&gt;For clusters running older Databricks runtime versions, such as 13.3, you can still implement upserting patterns effectively, even though they may not support the latest features like primary and foreign key constraints available in newer runtimes.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;One common upserting pattern involves using the &lt;CODE&gt;MERGE INTO&lt;/CODE&gt; statement, which allows you to merge a source dataset into a target dataset based on a specified condition. This pattern is useful for handling both inserts and updates in a single operation. Here is a basic example of how you can use the &lt;CODE&gt;MERGE INTO&lt;/CODE&gt; statement:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MERGE INTO target_table AS target
USING source_table AS source
ON target.id = source.id
WHEN MATCHED THEN
  UPDATE SET target.column1 = source.column1, target.column2 = source.column2
WHEN NOT MATCHED THEN
  INSERT (id, column1, column2) VALUES (source.id, source.column1, source.column2)&lt;/LI-CODE&gt;
&lt;P&gt;This approach ensures that if a record with the same &lt;CODE&gt;id&lt;/CODE&gt; exists in the target table, it will be updated with the values from the source table. If the record does not exist, it will be inserted.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 16:12:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/99393#M39982</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-11-19T16:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: PKEY Upserting Pattern With Older Runtimes</title>
      <link>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/99397#M39984</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/88823"&gt;@Walter_C&lt;/a&gt;&amp;nbsp; mentioned, merge is a a proper way to perform upsert. I just want to add that in Databricks primary and foreign constraints are informational only constraints and thus are not enforced. So,&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/96188"&gt;@ChristianRRL&lt;/a&gt;&amp;nbsp;be aware of that fact, because I see a lot of folks from RDBMS world that ran into issues, because they assumed that it works like in standard RDBMS engine.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 16:46:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pkey-upserting-pattern-with-older-runtimes/m-p/99397#M39984</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2024-11-19T16:46:58Z</dc:date>
    </item>
  </channel>
</rss>

