0

I am trying to use table.column LIKE '%[A-Za-z]% in Databricks notebook, but it returns no value.

It worked in SQL server, but it seems it's not working in Pysql.

Does anyone know what's the alternative in Databricks?

Alex Ott
  • 80,552
  • 8
  • 87
  • 132

1 Answers1

1

The LIKE function has a limited functionality, so you need to use rlike instead:

select * .... where column rlike '.*[A-Za-z].*'

Update: real example:

%python
df = spark.createDataFrame([{'id': 1, 's':'12323'}, {'id': 1, 's':'123T23'}], 
  schema='id int, s string')
df.createOrReplaceTempView("rlike_test")

and query:

%sql
select * from rlike_test where s rlike '.*[A-Za-z].*'

here is result of execution:

enter image description here

Alex Ott
  • 80,552
  • 8
  • 87
  • 132