find_in_set function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns the position of a string within a comma-separated list of strings.

Syntax

find_in_set(searchExpr, sourceExpr)

Arguments

  • searchExpr: A STRING expression specifying the "word" to be searched.
  • sourceExpr: A STRING expression with commas separating "words".

Returns

An INTEGER. The resulting position is 1-based and points to the first letter of the match. If no match is found for searchExpr in sourceExpr or searchExpr contains a comma, 0 is returned.

Examples

> SELECT find_in_set('ab','abc,b,ab,c,def');
 3