meitale
meitale

Reputation: 157

How to check if we have digits in column

I have this script:

df1 = spark.sql("select * from table where field LIKE '%[0-9]%'")
display(df1)

This gives me empty DF. I have table contains:
enter image description here

Upvotes: 0

Views: 443

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269953

If you want to return rows where the field has at least one digit, then you should use regular expressions. That is RLIKE and regular expression syntax:

select *
from table
where field rlike '[0-9]'

None of your fields contain the subquery '[0-9]' so none match like, which does not support [].

Upvotes: 3

Related Questions