cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into delta table fails

elgeo
Valued Contributor II

Hello experts. We are trying to execute an insert command with less columns than the target table:

Insert into table_name( col1, col2, col10)

Select col1, col2, col10

from table_name2

However the above fails with:

Error in SQL statement: DeltaAnalysisException: Column col3 is not specified in INSERT

Do you know if INSERT using a subquery requires all the columns of the target table specified?

1 ACCEPTED SOLUTION

Accepted Solutions

UmaMahesh1
Honored Contributor III

Hi @ELENI GEORGOUSI​ 

Yes. When you are doing an insert, your provided schema should match with the target schema else it would throw an error.

But you can still insert the data using another approach. Create a dataframe with your data having less columns and when writing that data into the target path, enable the mergeSchema option. This way even if you are adding new columns or removing columns, data would not be lost.

Hope this helps.

Cheers.

Uma Mahesh D

View solution in original post

1 REPLY 1

UmaMahesh1
Honored Contributor III

Hi @ELENI GEORGOUSI​ 

Yes. When you are doing an insert, your provided schema should match with the target schema else it would throw an error.

But you can still insert the data using another approach. Create a dataframe with your data having less columns and when writing that data into the target path, enable the mergeSchema option. This way even if you are adding new columns or removing columns, data would not be lost.

Hope this helps.

Cheers.

Uma Mahesh D

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group