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: 

IDENTITY column duplication when using BY DEFAULT parameter

Leszek
Contributor

Hi, I created delta table with identity column using this syntax:

Id BIGINT GENERATED BY DEFAULT AS IDENTITY

My steps:

1) Created table with Id using syntax above.

2) Added two rows with Id = 1 and Id = 2 (BY DEFAULT allows to do that).

3) Run Insert (without specifying Id column)

My result:

I have duplicated Id's:

image.pngDocumentation (https://docs.microsoft.com/en-us/azure/databricks/sql/language-manual/sql-ref-syntax-ddl-create-table-using#parameters) says:

"When ALWAYS is used, you cannot provide your own values for the identity column." - so, I'm using BY DEFAULT because this allows to do that.

Is that suppose to work that way? I thought that identity is identity 🙂

And another quote from docs:

"When you write to the table, and do not provide values for the identity column, it will be automatically assigned a unique and statistically increasing value"

1 REPLY 1

dileep_vikram
New Contributor II

Use below alter command to sync the identity column.

alter table table_name change column col_name sync identity

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!