cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Table ID not preserved using CREATE OR REPLACE TABLE

shanisolomonron
New Contributor II

The When to replace a table documentation states that using CREATE OR REPLACE TABLE should preserve the tableโ€™s identity:

Table contents are replaced, but the table identity is maintained.

However, in my recent test the table ID changed after running this command. Is this expected behavior?

For example, the transaction log shows:

  • Version 0:

    {"metaData":{"id":"6a085d18-3aef-4c4c-890b-fb4a6f9d6888", ...}}
  • Version 2: (post command)

    {"metaData":{"id":"e3f5d990-2c03-483e-8cd3-a772d5d87e93", ...}}

Should CREATE OR REPLACE TABLE ever generate a new table ID, or is this a bug?

3 REPLIES 3

nayan_wylde
Honored Contributor III

Yes that's correct. The table identity is preserved in case of delta tables. If the table is non delta it will not be preserved.

Can you also confirm if the table you are recreating have schema changes. Because sometimes CREATE OR REPLACE TABLE with change in column definitions, table properties  or format may be treated as drop and recreate operation internally which might result in id lost. 

szymon_dybczak
Esteemed Contributor III

HI @nayan_wylde , @shanisolomonron 

I don't think it works in the way you've described. We can easily check this. Each time I execute following code I get new id:

%sql
CREATE OR REPLACE TABLE databricks_demo_ws.default.my_table (
  id int,
  name string
)

So, first time I've exectued above code I got id: f2a57c4-152b-46c4-9dd5-b1e945846d71

Then I execute above code second time. As you can see, no major schema changes occured but still I got completly new id: 641cacab-7175-4f44-98cc-fad9ba8aa66e

I think what they refer in docs as table identity is more related to catalog / metadata identity (not necessarily the same as the internal delta log id). Because all other things mentioned in documentation hold:

  • The table history is retained, and I can revert the table to an earlier version with the RESTORE command.
  • The operation is a single transaction, so there is never a time when the table doesn't exist.

 

shanisolomonron
New Contributor II

Waiting for a databricks employee to clarify this item. 

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now