split_part

Description

Splits a given string at a specified delimiter character and returns the requested part.

Selecting the part to return is 1-based, or counting from 1. A part of “0” will be treated as “1”, but it is recommended not to use “0” to avoid confusion. If part is a negative value, the parts are counted backward from the end of the string. If any parameter is null, this function returns null.

Return type

string

Domain

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

Categories

Usage

split_part(value, delimiter, part)

Argument

Type

Optional

Repeatable

Restrictions

value

string

no

no

none

delimiter

string

no

no

constant

part

int64

no

no

none

Examples

split_part("03/04/2021", "/", 2)

This splits the given string by slashes, returning item number 2, which is “04” (one-based indexing.)

split_part("The quick brown fox jumped over the lazy dog", " ", 0)

This splits the given string by spaces, returning the first item number (“The”) because 0 is automatically interpolated to 1 (one-based indexing).