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: 

Adding column as StructType

Gilg
Contributor II

Hi Team,

Just wondering, how can I add a column to an existing table.

I'd tried the below script but giving me an error:

ParseException:

[PARSE_SYNTAX_ERROR] Syntax error at or near '<'(line 1, pos 121)

ALTER TABLE table_clone ADD COLUMNS col_name1 STRUCT<

-------------------------------------------------------------------------------------------------------------------------^^^

$type:STRING,

$values:ARRAY<STRING>

>

ALTER TABLE table_clone 
ADD COLUMNS col_name1 STRUCT<
        $type: STRING,
        $values: ARRAY<STRING>
    >

Cheers,

G

1 REPLY 1

Anonymous
Not applicable

@Gil Gonong​ :

In Databricks, you can add a column to an existing table using the ALTER TABLE statement in SQL. Here is an example:

ALTER TABLE table_clone ADD COLUMN col_name1 STRUCT<
    type: STRING,
    values: ARRAY<STRING>
>

Note that you need to have the necessary privileges to modify the table. If you are not the owner of the table, you need to have been granted the ALTER privilege by the owner or an administrator.

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!