substring

Description

Extracts characters from a string, starting at an index.

Negative indices count from the end of the string. Positive indices start at 0. Takes an optional length parameter.

Returns an empty string if the optional length parameter is not positive.

Return type

string

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

substring(value, start, [ length ])

Argument

Type

Optional

Repeatable

Restrictions

value

string

no

no

none

start

int64

no

no

none

length

int64

yes

no

none

Examples

make_col substr:substring('mystring', 2)

Returns the substring starting from position 2 till the end of the string, which is ‘string’.

make_col substr:substring('mystring', 2, 4)

Returns the substring starting from position 2 with a length of 4, which is ‘stri’.

make_col substr:substring('mystring', -4, 2)

Returns the substring starting from four characters from the end with a length of 2, which is ‘ri’.

make_col substr:substring('mystring', 2, -2)

Returns an empty string as the length is not positive.