Skip to content
Advertisement

Databricks error when change type column from string to numeric

I have a error like:

com.databricks.backend.common.rpc.DatabricksExceptions$SQLExecutionException: org.apache.spark.sql.catalyst.parser.ParseException: no viable alternative at input ‘alter table x9concsheet5 Add netto_resultaat'(line 1, pos 29)*

when i run this sql command in databricks:

%sql alter table x9concsheet5 Add netto_resultaat numeric(17,2)

The requirement is to change the column type from string to numeric from the temporary table x9concsheet5.

Any suggestions?

Advertisement

Answer

you can use following command to modify the data type

ALTER TABLE table_name CHANGE old_col_name new_col_name new_data_type

but when are you are tying to modify the column type from string to decimal(17,2), you can do following step ,

  1. create a new column with transforming netto_resultaat with numeric value from string
  2. dropping existing string column
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement