<?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: TABLE_OR_VIEW_ALREADY_EXISTS when using saveAsTable with append mode in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131396#M49077</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/179612"&gt;@WiliamRosa&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;for the reply. I will probably keep mergeSchema then.&amp;nbsp; If the options are incompatible or might cause issues I wish there was a warning of sorts. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Sep 2025 12:24:09 GMT</pubDate>
    <dc:creator>Mikkel</dc:creator>
    <dc:date>2025-09-09T12:24:09Z</dc:date>
    <item>
      <title>TABLE_OR_VIEW_ALREADY_EXISTS when using saveAsTable with append mode</title>
      <link>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131374#M49069</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran into an unexpected error while writing a DataFrame to a managed table&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN&gt;df.write \
  .mode(&lt;SPAN class=""&gt;"append") \
  .option(&lt;SPAN class=""&gt;"overwriteSchema", &lt;SPAN class=""&gt;"true") \
  .option(&lt;SPAN class=""&gt;"mergeSchema", &lt;SPAN class=""&gt;"true") \
  .saveAsTable(bsr_sink_table_fqn)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Instead of appending, Spark attempted to &lt;STRONG&gt;create the table again and failed with.&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;```[TABLE_OR_VIEW_ALREADY_EXISTS] Cannot create table or view `customer__castan__production`.`insights`.`used_bsr_insights`&lt;BR /&gt;because it already exists. &lt;BR /&gt;Choose a different name, drop the existing object, add the IF NOT EXISTS clause, ...&lt;BR /&gt;SQLSTATE: 42P07```&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;The table was actually created but empty.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why this is confusing:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;The .mode("append") call should normally append to the table if it exists, not trigger a CREATE TABLE.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;The presence of .option("overwriteSchema", "true") and .option("mergeSchema", "true") may be causing Databricks to attempt a DDL operation on the existing table, which conflicts with append mode.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Questions for the community:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Is this expected behavior when combining append with overwriteSchema/mergeSchema?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Could concurrent writers to the same target table trigger this error even in append mode?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Is there a recommended way to safely append with schema evolution without hitting this TABLE_OR_VIEW_ALREADY_EXISTS error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Sep 2025 10:45:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131374#M49069</guid>
      <dc:creator>Mikkel</dc:creator>
      <dc:date>2025-09-09T10:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: TABLE_OR_VIEW_ALREADY_EXISTS when using saveAsTable with append mode</title>
      <link>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131378#M49070</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/100165"&gt;@Mikkel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I guess this is expected behaviour. Check following excerpt from Jacek Laskowski's Delta Lake internals book.&lt;BR /&gt;It seems that setting overwriteSchema to true will wipe out the old schema and let you create a completely new table. So it doesn't make sense to use this option together with append - it should be used with overwrite mode.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="szymon_dybczak_0-1757415544626.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/19859i7183550B19989728/image-size/medium?v=v2&amp;amp;px=400" role="button" title="szymon_dybczak_0-1757415544626.png" alt="szymon_dybczak_0-1757415544626.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And yes, if multiple concurrent writers will try to write to the same target table then I guess you will encounter this error because each of them will basically try to recreate the table.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 11:03:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131378#M49070</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-09-09T11:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: TABLE_OR_VIEW_ALREADY_EXISTS when using saveAsTable with append mode</title>
      <link>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131382#M49073</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/100165"&gt;@Mikkel&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;I was testing this myself before posting and ran into exactly what &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp; described. overwriteSchema basically tries to recreate the table even when you’re using append. If all you need is schema evolution, stick with mergeSchema — it only supports additive changes like adding new columns. For anything else (renames, type changes, etc.), you’ll need to run an ALTER TABLE first and then append.&lt;BR /&gt;Tks for sharing&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 11:27:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131382#M49073</guid>
      <dc:creator>WiliamRosa</dc:creator>
      <dc:date>2025-09-09T11:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: TABLE_OR_VIEW_ALREADY_EXISTS when using saveAsTable with append mode</title>
      <link>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131396#M49077</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/179612"&gt;@WiliamRosa&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;for the reply. I will probably keep mergeSchema then.&amp;nbsp; If the options are incompatible or might cause issues I wish there was a warning of sorts. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 12:24:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/table-or-view-already-exists-when-using-saveastable-with-append/m-p/131396#M49077</guid>
      <dc:creator>Mikkel</dc:creator>
      <dc:date>2025-09-09T12:24:09Z</dc:date>
    </item>
  </channel>
</rss>

