cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

SQL CONTAINS Function is not working on Databricks

Prasann_gupta
New Contributor

I am trying to use sql CONTAINS function in my sql query but it is throwing the below error :

AnalysisException: Undefined function: 'CONTAINS'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 14 pos

3 REPLIES 3

pvignesh92
Honored Contributor

In Spark SQL, the CONTAINS function is not a built-in function.

As an alternative, you can use the below inbuilt functions

  • LIKE function can be used to check whether a string contains a specific substring. The syntax is as follows:

Sample Code

SELECT * FROM table_name
WHERE column_name LIKE '%substring%'

  • INSTR function can be used to find the position of a substring within a string. If the substring is not found, the function returns 0. The syntax is as follows:

SELECT * FROM table_name WHERE INSTR(column_name, 'substring') > 0

Or the good old Regex

SELECT * FROM table_name
WHERE column_name RLIKE 'regexp_pattern'

Please let me know if this helps.

Lakshay
Databricks Employee
Databricks Employee

Hi @Prasann Guptaโ€‹ , Spark sql does not have CONTAINS as a built in function. The best option here would be to use LIKE function.

Anonymous
Not applicable

Hi @Prasann Guptaโ€‹ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group