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: 

Delta table with Varchar column vs string column

Hongbo
New Contributor III

Databricks support string data type. But I can still create delta table with varchar data type. Just wonder what is different between delta table with string and delta table with varchar:

-- delta table with string

CREATE TABLE persons(first_name STRING NOT NULL, last_name STRING NOT NULL, nickname STRING,
                       CONSTRAINT person_pk PRIMARY KEY (first_name, last_name)
                       );
-- delta table with varchar
CREATE TABLE persons(first_name STRING NOT NULL, last_name varchar(50) NOT NULL, nickname varchar(50),
                       CONSTRAINT person_pk PRIMARY KEY (first_name, last_name)
                       );
1 ACCEPTED SOLUTION

Accepted Solutions

erigaud
Honored Contributor

VARCHAR allows you to specify the size of the string expected in the column. 

This is useful when you know your column cannot exceed a set size (ie for a name, a code etc).

It is equivalent to a CHECK contraint on the size. Trying to insert a value that exceeds the size given results in the following error : 

com.databricks.sql.transaction.tahoe.schema.DeltaInvariantViolationException: Exceeds char/varchar type length limitation. Failed check: (isnull('last_name) OR (length('last_name) <= 50)).
 

View solution in original post

2 REPLIES 2

erigaud
Honored Contributor

VARCHAR allows you to specify the size of the string expected in the column. 

This is useful when you know your column cannot exceed a set size (ie for a name, a code etc).

It is equivalent to a CHECK contraint on the size. Trying to insert a value that exceeds the size given results in the following error : 

com.databricks.sql.transaction.tahoe.schema.DeltaInvariantViolationException: Exceeds char/varchar type length limitation. Failed check: (isnull('last_name) OR (length('last_name) <= 50)).
 

Thanks for the precision @erigaud ! 

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