<?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 Re: How to use uuid in SQL merge into statement in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19764#M13297</link>
    <description>&lt;P&gt;you might wanna look into an identity column, which is possible now in delta lake.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.databricks.com/blog/2022/08/08/identity-columns-to-generate-surrogate-keys-are-now-available-in-a-lakehouse-near-you.html" target="test_blank"&gt;https://www.databricks.com/blog/2022/08/08/identity-columns-to-generate-surrogate-keys-are-now-available-in-a-lakehouse-near-you.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 13:21:02 GMT</pubDate>
    <dc:creator>-werners-</dc:creator>
    <dc:date>2022-11-30T13:21:02Z</dc:date>
    <item>
      <title>How to use uuid in SQL merge into statement</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19763#M13296</link>
      <description>&lt;P&gt;I have a Merge into statement that I use to update existing entries or create new entries in a dimension table based on a natural business key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When creating new entries I would like to also create a unique uuid for that entry that I can use to crossreference with other tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However the merge into statement doesn't allow me to use `uuid()` .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example code: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%sql WITH newData AS (
  SELECT
    MAC,
    IP,
    Name
  FROM
    bronze.ComputerLogs
) MERGE INTO silver.d_ComputerInfo AS s USING newData ON s.MAC = newData.MAC
WHEN MATCHED THEN
UPDATE
SET
  s.IP = newData.IP,
  s.Name = newData.Name,
  WHEN NOT MATCHED THEN
INSERT
  (
    ComputerInfoId,
    MAC,
    IP,
    Name
  )
VALUES
  (uuid(), MAC, IP, NAME)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This gives the following error&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;AnalysisException: nondeterministic expressions are only allowed in
Project, Filter, Aggregate, Window, or Generate, but found:
...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way to bypass this and still use randomly generated ids?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 10:13:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19763#M13296</guid>
      <dc:creator>Merchiv</dc:creator>
      <dc:date>2022-11-30T10:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use uuid in SQL merge into statement</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19764#M13297</link>
      <description>&lt;P&gt;you might wanna look into an identity column, which is possible now in delta lake.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.databricks.com/blog/2022/08/08/identity-columns-to-generate-surrogate-keys-are-now-available-in-a-lakehouse-near-you.html" target="test_blank"&gt;https://www.databricks.com/blog/2022/08/08/identity-columns-to-generate-surrogate-keys-are-now-available-in-a-lakehouse-near-you.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 13:21:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19764#M13297</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-11-30T13:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use uuid in SQL merge into statement</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19765#M13298</link>
      <description>&lt;P&gt;We have used tested this, but these are incremental keys that require syncing if we manually insert some extra keys, which makes them not practical.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 08:41:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19765#M13298</guid>
      <dc:creator>Merchiv</dc:creator>
      <dc:date>2022-12-01T08:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use uuid in SQL merge into statement</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19766#M13299</link>
      <description>&lt;P&gt;A ok, I thought you were looking for that.&lt;/P&gt;&lt;P&gt;In that case: &lt;/P&gt;&lt;P&gt;have you tested adding the UUID in the newData DF beforehand?&lt;/P&gt;&lt;P&gt;Because it could be a limitiation of the merge itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 08:59:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-uuid-in-sql-merge-into-statement/m-p/19766#M13299</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-12-01T08:59:42Z</dc:date>
    </item>
  </channel>
</rss>

