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: 

insert into a table with an identity column fails

nbakh
New Contributor II

i am trying to insert into a table with an identity column using a select query.

However, if i include the identity column or ignore the identity column in my insert it throws errors. Is thee a way to insert into select * from a table if the insert table has an identity column?

%sql

CREATE OR REPLACE TABLE demo (

 id BIGINT GENERATED ALWAYS AS IDENTITY,

 product_type STRING,

 sales BIGINT

);

%sql

insert into demo_test

SELECT id,product_type, sales from demo

AnalysisException: Providing values for GENERATED ALWAYS AS IDENTITY column id is not supported.

%sql

insert into demo_test

SELECT product_type, sales from demo

nalysisException: Cannot write to 'spark_catalog.default.demo_test', not enough data columns; target table has 3 column(s) but the inserted data has 2 column(s)

4 REPLIES 4

Debayan
Esteemed Contributor III
Esteemed Contributor III

Hi, Looks like it is not supported.

Please refer: https://github.com/delta-io/delta/issues/1215

Kaniz_Fatma
Community Manager
Community Manager

Hi @nauman bakhrani​​, We haven’t heard from you since the last response from @Debayan Mukherjee​ , and I was checking back to see if you have a resolution yet.

If you have any solution, please share it with the community, as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

Hubert-Dudek
Esteemed Contributor III

instead of using

GENERATED ALWAYS AS IDENTITY,

you need to use

GENERATED BY DEFAULT AS IDENTITY

karan_singh
New Contributor II

Hi, 

Specify insert columns as below

 
%sql
INSERT INTO demo_test (product_type, sales)
SELECT product_type, sales FROM demo

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!