szymon_dybczak
Esteemed Contributor III

Hi  @Taj2019 ,

ALTER TABLE ... ALTER COLUMN ... TYPE is supported only for Delta tables and only for supported type-widening conversions. Databricks currently supports conversions such as FLOAT -> DOUBLE, integer types -> DECIMAL, and increasing the precision/scale of an existing DECIMAL.
It does
not list DOUBLE → DECIMAL as a supported in-place conversion, so enabling delta.enableTypeWidening will not solve this particular change.

The easiest fix would be to overwrite or recreate this table from scratch.

from pyspark.sql import functions as F

(
    spark.read.table("catalog.schema.my_table")
    .withColumn("col1", F.col("col1").cast("decimal(31,5)"))
    .write
    .mode("overwrite")
    .option("overwriteSchema", "true")
    .saveAsTable("catalog.schema.my_table")
)



If my answer was helpful, please consider marking it as accepted solution.