<?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: CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59756#M31505</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/76914"&gt;@Ayushi_Suthar&lt;/a&gt;, I am talking about the link you shared - &lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.html#:~:text=Parameters-,REPLACE,REPLACE%20preserves%20the%20table%20history.,-Note" target="_self"&gt;click here&lt;/A&gt;. It says the following&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;REPLACE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If specified replaces the table and its content if it already exists. This clause is only supported for Delta Lake tables.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;REPLACE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;preserves the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://docs.databricks.com/en/delta/history.html" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;table history&lt;/SPAN&gt;&lt;/A&gt;.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is why I think that Delta does not delete the files that already exist at the location, in case they might contain the history of the previous version of the table. And since it does not need to delete the data that is already there in the location it can create a managed table without any error. Whereas other formats need to delete the data and produce errors. Am I right?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Feb 2024 06:35:12 GMT</pubDate>
    <dc:creator>Dhruv-22</dc:creator>
    <dc:date>2024-02-09T06:35:12Z</dc:date>
    <item>
      <title>CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does</title>
      <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59667#M31468</link>
      <description>&lt;P&gt;I am working on Azure Databricks, with Databricks Runtime version being -&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#993300"&gt;14.3 LTS (includes Apache Spark 3.5.0, Scala 2.12)&lt;/FONT&gt;. I am facing the following issue.&lt;/P&gt;&lt;P&gt;Suppose I have a view named&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#993300"&gt;v1&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and a database&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#993300"&gt;f1_processed&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;created from the following command.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;CREATE&lt;/SPAN&gt; DATABASE IF &lt;SPAN class=""&gt;NOT&lt;/SPAN&gt; &lt;SPAN class=""&gt;EXISTS&lt;/SPAN&gt; f1_processed
LOCATION "abfss://processed@formula1dl679student.dfs.core.windows.net/"&lt;/PRE&gt;&lt;P&gt;Then if I try to create a table at a location that already exists using the command below.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class=""&gt;TABLE&lt;/SPAN&gt; f1_processed.circuits 
&lt;SPAN class=""&gt;AS&lt;/SPAN&gt; 
&lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class=""&gt;*&lt;/SPAN&gt; &lt;SPAN class=""&gt;FROM&lt;/SPAN&gt; v1;&lt;/PRE&gt;&lt;P&gt;I get the following error&lt;/P&gt;&lt;PRE&gt;[DELTA_CREATE_TABLE_WITH_NON_EMPTY_LOCATION] Cannot create table ('`spark_catalog`.`f1_processed`.`circuits`'). 
The associated location ('abfss://processed@formula1dl679student.dfs.core.windows.net/circuits') 
is not empty and also not a Delta table. SQLSTATE: 42601&lt;/PRE&gt;&lt;P&gt;However, if I replace CREATE with CREATE OR REPLACE, then the command runs fine. So the following code runs fine.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class=""&gt;OR&lt;/SPAN&gt; REPLACE &lt;SPAN class=""&gt;TABLE&lt;/SPAN&gt; f1_processed.circuits 
&lt;SPAN class=""&gt;AS&lt;/SPAN&gt; 
&lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class=""&gt;*&lt;/SPAN&gt; &lt;SPAN class=""&gt;FROM&lt;/SPAN&gt; v1;&lt;/PRE&gt;&lt;P&gt;The table didn't exist before. So&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#993300"&gt;CREATE OR REPLACE&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is also basically creating a table. Shouldn't the behaviour be consistent with the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#993300"&gt;CREATE&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command?&lt;/P&gt;&lt;P&gt;Also, the table creation is only happening for delta format. If I specify the format to be any other like parquet, then it fails.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/replace-table-as-select-is-not-working-with-parquet-whereas-it/td-p/59666" target="_self"&gt;Checkout this question&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is it a bug? Any help is appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 09:33:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59667#M31468</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2024-02-08T09:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does</title>
      <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59710#M31496</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/99515"&gt;@Dhruv-22&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the information you shared above, the "CREATE OR REPLACE" and "CREATE" commands in Databricks do have different behaviours, particularly when it comes to handling tables with specific target locations.&lt;/P&gt;
&lt;P&gt;The "CREATE OR REPLACE" command is designed to either create a new table or replace an existing one. On the other hand, the "CREATE" command is used to create a new table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer this documentation for more details:&amp;nbsp;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.html" target="_blank"&gt;https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps you and please leave a like if this helps, followups are appreciated.&lt;BR /&gt;Kudos&lt;BR /&gt;Ayushi&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 14:41:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59710#M31496</guid>
      <dc:creator>Ayushi_Suthar</dc:creator>
      <dc:date>2024-02-08T14:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does</title>
      <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59718#M31498</link>
      <description>&lt;P&gt;Okay, I read the documentation. I think since REPLACE maintains the version history, even if the location has some files already it keeps them for that purpose. Am I right?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 17:09:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59718#M31498</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2024-02-08T17:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does</title>
      <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59747#M31504</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/99515"&gt;@Dhruv-22&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems there might be some confusion. The REPLACE command you're referring to is not explicitly mentioned in the context. However, there are references to the version history in Delta Lake tables.&lt;/P&gt;
&lt;P&gt;In Delta Lake tables, each operation that modifies a table creates a new table version. You can use this history information to audit operations, rollback a table, or query a table at a specific point in time using time travel. There's also a RESTORE command that can restore a Delta table to its earlier state, but again, this doesn't directly relate to a REPLACE command.&lt;/P&gt;
&lt;P&gt;I hope this helps you and leave a like if this helps, followups are appreciated.&lt;BR /&gt;Kudos&lt;BR /&gt;Ayushi&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 04:55:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59747#M31504</guid>
      <dc:creator>Ayushi_Suthar</dc:creator>
      <dc:date>2024-02-09T04:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: CREATE TABLE does not overwrite location whereas CREATE OR REPLACE TABLE does</title>
      <link>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59756#M31505</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/76914"&gt;@Ayushi_Suthar&lt;/a&gt;, I am talking about the link you shared - &lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.html#:~:text=Parameters-,REPLACE,REPLACE%20preserves%20the%20table%20history.,-Note" target="_self"&gt;click here&lt;/A&gt;. It says the following&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;REPLACE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If specified replaces the table and its content if it already exists. This clause is only supported for Delta Lake tables.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;REPLACE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;preserves the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://docs.databricks.com/en/delta/history.html" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;table history&lt;/SPAN&gt;&lt;/A&gt;.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That is why I think that Delta does not delete the files that already exist at the location, in case they might contain the history of the previous version of the table. And since it does not need to delete the data that is already there in the location it can create a managed table without any error. Whereas other formats need to delete the data and produce errors. Am I right?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 06:35:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-table-does-not-overwrite-location-whereas-create-or/m-p/59756#M31505</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2024-02-09T06:35:12Z</dc:date>
    </item>
  </channel>
</rss>

