description |
---|
Returns a substring of an expression before the specified number of delimiters occurs. |
- 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 %}
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.