<?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: Are MERGE INTO inserts supported when the delta table has an identity column ? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32296#M23540</link>
    <description>&lt;P&gt;I use 11.2 runtime. identity column created as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;dl_id   BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the pyspark code is an upsert:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;t.alias("ec").merge(df.alias("uc"), "ec.dl_id = uc.dl_id") \
            .whenMatchedUpdateAll() \
            .whenNotMatchedInsertAll() \
            .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Sep 2022 10:08:28 GMT</pubDate>
    <dc:creator>VaDim</dc:creator>
    <dc:date>2022-09-08T10:08:28Z</dc:date>
    <item>
      <title>Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32294#M23538</link>
      <description>&lt;P&gt;I can't seem to make it work as I keep getting:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DeltaInvariantViolationException: NOT NULL constraint violated for column: dl_id.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 09:33:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32294#M23538</guid>
      <dc:creator>VaDim</dc:creator>
      <dc:date>2022-09-08T09:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32295#M23539</link>
      <description>&lt;P&gt;I would think it is supported as that is the whole purpose of the ID column, not providing the value yourself.&lt;/P&gt;&lt;P&gt;I haven't tested it though.&lt;/P&gt;&lt;P&gt;But what version of databricks do you use? You need a pretty recent version (10.4+).&lt;/P&gt;&lt;P&gt;Also: how is the identity column created?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 09:49:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32295#M23539</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-09-08T09:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32296#M23540</link>
      <description>&lt;P&gt;I use 11.2 runtime. identity column created as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;dl_id   BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the pyspark code is an upsert:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;t.alias("ec").merge(df.alias("uc"), "ec.dl_id = uc.dl_id") \
            .whenMatchedUpdateAll() \
            .whenNotMatchedInsertAll() \
            .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:08:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32296#M23540</guid>
      <dc:creator>VaDim</dc:creator>
      <dc:date>2022-09-08T10:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32297#M23541</link>
      <description>&lt;P&gt;Hm, and both ec and uc have id's always filled in?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:21:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32297#M23541</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-09-08T10:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32298#M23542</link>
      <description>&lt;P&gt;`ec` - always. `uc` - not. because `uc` might contain new data that needs appended.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:25:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32298#M23542</guid>
      <dc:creator>VaDim</dc:creator>
      <dc:date>2022-09-08T10:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32299#M23543</link>
      <description>&lt;P&gt;I think that is the issue.  uc contains a column which is supposed to be an id, but you cannot pass it to the merge as it is generated.&lt;/P&gt;&lt;P&gt;What happens if you merge on the natural key?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:29:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32299#M23543</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-09-08T10:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32300#M23544</link>
      <description>&lt;P&gt;I haven't tried but I suspect it will fail with the same message on INSERT because uc.dl_id is  NULL for some rows and `whenNotMatchedInsertAll` will attempt to insert a value for dl_id field instead of generating one (as if it has been user provided).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the meantime I found a workaround: explicitly set the column mapping and do not include one for `dl_id`.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cols2update is a dict with column mapping except dl_id, it works.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;t.alias("ec").merge(df.alias("uc"), "ec.dl_id = uc.dl_id") \
            .whenMatchedUpdate(set=cols2update) \
            .whenNotMatchedInsert(values=cols2update) \
            .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:41:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32300#M23544</guid>
      <dc:creator>VaDim</dc:creator>
      <dc:date>2022-09-08T10:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32301#M23545</link>
      <description>&lt;P&gt;I was just typing this workaround &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  Because the id col is defined as GENERATED ALWAYS AS IDENTITY it can never be updated.  If you then use UpdateAll it will generate an error.&lt;/P&gt;&lt;P&gt;remove the Id col from the columns to be updated.&lt;/P&gt;&lt;P&gt;This is the way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:43:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32301#M23545</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-09-08T10:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Are MERGE INTO inserts supported when the delta table has an identity column ?</title>
      <link>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32302#M23546</link>
      <description>&lt;P&gt;if you are using 'delta.columnMapping.mode' = 'name'  on your table  i could not get it to work, without that line ..  for the not matched .. WHEN NOT MATCHED&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;THEN INSERT (columnname,columnName2) values(columnname,columnName2)&lt;/P&gt;&lt;P&gt;WHEN MATCHED&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then UPDATE SET (target.columnname = source.columnname,target.columnname2 = source.columnname2)   That worked for me.. Leave the id column out of any of these&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 01:35:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/are-merge-into-inserts-supported-when-the-delta-table-has-an/m-p/32302#M23546</guid>
      <dc:creator>byrdman</dc:creator>
      <dc:date>2022-09-09T01:35:39Z</dc:date>
    </item>
  </channel>
</rss>

