SUBSTRING function
Returns the substring of an expression that starts at a position and is of a certain length.
Syntax
SUBSTRING(expression, position, length)
Arguments
expression: The string.position: The 1-based index from which the substring starts.length: The length of the substring. If omitted, it will go until the end of the expression.
Returns
A VARCHAR.
Examples
> SELECT SUBSTRING('abc', 1);
'abc'
> SELECT SUBSTRING('abc', 1, 1);
'a'
> SELECT SUBSTRING('abc', 5);
''
Notes
Negative Position Behavior
Negative integer literals are not supported.
It is possible to have a negative position when using a function.
Vertica will start from the imaginary places before the actual start of the string.
Example:
abcwith a position of-1and length of3returnsa
Databricks will start counting backwards from the end of the string.
Example:
abcwith a positon of-2and length of2returnsbc
Negative Length Behavior
Negative integer literals are not supported.
It is possible to have a negative length when using a function.
Vertica will throw an exception.
Databricks will return an empty string.