Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.32 KB

substring_index.md

File metadata and controls

37 lines (28 loc) · 1.32 KB
description
Returns a substring of an expression before the specified number of delimiters occurs.

SUBSTRING_INDEX

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

{% code title="SUBSTRING_INDEX example" %}

SELECT SUBSTRING_INDEX('spice.ai', '.', 2)
-- EXPR$0
-- spice

{% endcode %}

{% code title="SUBSTRING_INDEX example" %}

SELECT SUBSTRING_INDEX('spice.ai', '.', -2)
-- EXPR$0
-- spice.ai

{% endcode %}

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.