cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Esteemed Contributor
Esteemed Contributor

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!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.