cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
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.

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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.