3

I am trying to add a new column of Array Type to the table with default value.

%sql
ALTER TABLE testdb.tabname ADD COLUMN new_arr_col ARRAY DEFAULT ['A','B','C'];

But it says that the data type in not supported

Error in SQL statement: ParseException: 
DataType array is not supported.(line 1, pos 54)

== SQL ==
ALTER TABLE testdb.dim_category ADD COLUMN c_cat_area ARRAY

So, there is no way we can add an array column directly to the table? Kindly assist me on this. Thanks in advance!

3
  • 1
    This DEFAULT keyword makes me think you use Databricks (not a vanilla Delta Lake on Spark 3.2)? Commented Aug 20, 2022 at 14:33
  • This is Delta lake spark. Spark v3.2.1. Is this way of applying default value wrong? Commented Aug 21, 2022 at 3:24
  • I don't think DEFAULT is supported in Delta Lake OSS. It will only work in Databricks. Commented Aug 21, 2022 at 11:54

1 Answer 1

7

The reason for this error is that complex types (e.g. ARRAY) require another type to be specified (cf. SqlBase.g4):

dataType
    : complex=ARRAY '<' dataType '>'                            #complexDataType
    | complex=MAP '<' dataType ',' dataType '>'                 #complexDataType
    | complex=STRUCT ('<' complexColTypeList? '>' | NEQ)        #complexDataType
    | INTERVAL from=(YEAR | MONTH) (TO to=MONTH)?               #yearMonthIntervalDataType
    | INTERVAL from=(DAY | HOUR | MINUTE | SECOND)
      (TO to=(HOUR | MINUTE | SECOND))?                         #dayTimeIntervalDataType
    | identifier ('(' INTEGER_VALUE (',' INTEGER_VALUE)* ')')?  #primitiveDataType
    ;

In your case, it'd be as follows:

ARRAY<CHAR(3)>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.