SQL CONTAINS Function is not working on Databricks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 10:40 PM
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
- Labels:
-
SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 12:53 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:38 AM
Hi @Prasann Gupta , Spark sql does not have CONTAINS as a built in function. The best option here would be to use LIKE function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 05:47 PM
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!

