Skip to main content

SUBSTRING_INDEX

Categories: String

SUBSTRING_INDEX

Returns a substring of an expression before the specified number of delimiter occurs.

Syntax

SUBSTRING_INDEX(expression varchar, delimiter varchar, count integer) → varchar

  • expression: Base expression to extract substring from.
  • delimiter: The string to search for.
  • count: An INTEGER expression to count the delimiters.

Examples

SUBSTRING_INDEX example
SELECT SUBSTRING_INDEX('www.dremio.com', '.', 2)
-- www.dremio
SUBSTRING_INDEX example
SELECT SUBSTRING_INDEX('www.dremio.com', '.', -2)
-- dremio.com

Usage Notes

This function performs a case-sensitive match when searching for the delimiter. The count expression can be a positive or negative number. If positive, this function returns the characters from the left of the expression up to the count of occurrences of the delimiter. If negative, this function returns the characters from the right of the expression up to the count of occurrences of the delimiter.