cornerstone347
cornerstone347

Reputation: 57

Filter like %[A-Za-z]% in databricks

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?

Upvotes: 1

Views: 2204

Answers (1)

Alex Ott
Alex Ott

Reputation: 87069

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

Upvotes: 2

Related Questions