I'm trying to convert my column of string data type to timestamp in my Azure databricks.
I'm using 10.4 LTS (includes Apache Spark 3.2.1, Scala 2.12) So I wrote the following query
Alter table convertToTimeStamp alter column FinalDate timestamp
My sample data looks like
|FinalDate |
|---------------------|
|2/18/2021 7:20:12 PM |
|2/22/2021 5:25:13 PM |
|4/23/2021 3:19:35 AM |
But I'm getting ParseException saying that
extraneous input 'timestamp' expecting {<EOF>, ';'}(line 1, pos 54)
Can you please guide me to resolve the issue?
Looking at the docs, it appears Databricks SQL doesn't support this operation.
You can see there is no option to alter the datatype in the documented syntax for
ALTER TABLE ... ALTER COLUMNThis is consistent with the error message, which suggests it's expecting a semicolon at the 54th character (i.e. after
alter column FinalDate).Here's an example of an older SO answer that describes how it's done in pyspark.