cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Columns with DEFAULT missing error during INSERT

Gim
Contributor

I am really confused about the DEFAULT capability of Databricks SQL. I looked at the documentation for the minimum required DBR to get the capability yet we still need to enable it as a table property? I updated my cluster's DBR from 12.2 to 13.1.

Anyway, that is already done. After having created my table, I am already set to do my INSERTs. Since I have set default values on 3 (out of 5) of my columns, I only provide the values for the two remaining columns. Yet for some reason, I am still forced to explicitly assign values to the columns with DEFAULTs assigned? What am I doing wrong?

Gim_0-1688465259125.png

 

 

CREATE OR REPLACE TABLE my_table (
  id BIGINT GENERATED BY DEFAULT AS IDENTITY,
  first_name STRING,
  last_name STRING,
  _is_active STRING DEFAULT 'Y',
  _start_date DATE DEFAULT CURRENT_DATE(),
  _end_date DATE DEFAULT NULL
)
TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'enabled', 'delta.minReaderVersion' = '2', 'delta.minWriterVersion'='7')
;

-- Initial data
INSERT INTO my_table (first_name, last_name)
SELECT fname, lname FROM src_table;

 

I also referred to this link

1 REPLY 1

BriceBuso
Contributor II

Hello @Gim

Got the same problem. 

Tried with the instruction "GENERATED ALWAYS AS (CAST(CURRENT_DATE() AS DATE))" but code is returning 

"Error in SQL statement: DeltaAnalysisException: current_date() cannot be used in a generated column"
 
If you find a solution other than generating the current date in your ingestion pipeline and inserting it with the data, please tell me 😁.
 
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.