How to remove specific character from string in spark-sql

Viewed 9292

I want to convert '123,456' to 123456 (string to int) by spark-sql.

I tried like this.

REPLACE('123,456', ',', '')

But it didn't work, because spark-sql don't permit REPLACE()

2 Answers

replace works as expected for me (Spark 2.3.0):

spark.sql("select int(replace('123,456', ',', '')) result").collect()
# [Row(result=123456)]
Related