substring_index function

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

Returns the substring of expr before count occurrences of the delimiter delim.


substring_index(expr, delim, count)


  • expr: A STRING or BINARY expression.

  • delim: An expression matching the type of expr specifying the delimiter.

  • count: An INTEGER expression to count the delimiters.


The result matches the type of expr.

If count is positive, everything to the left of the final delimiter (counting from the left) is returned.

If count is negative, everything to the right of the final delimiter (counting from the right) is returned.


> SELECT substring_index('', '.', 2);